We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3D maze in browser controlled by Small Basic
#81
(02-17-2025, 07:10 PM)litdev Wrote: AB,
...
2] Make sure that you leave sufficient Program.Delay after the animate, rotate or forward commands that it has fully completed.
3] The animate command is intended to do a rotation and movement to a new cell, to just do a rotation, use the rotate command.
...

Thank you for the hint.

I'll start testing this.  Shy
Reply
#82
AB,
Note that the rotate command is relative to current direction, so -90 is turn left and 90 is turn right - more like the Turtle commands.
[-] The following 1 user Likes litdev's post:
  • AbsoluteBeginner
Reply
#83
Hooray! My robot control code works fine!  Cool

The pause after sending a network request is 1000 ms.

Now I can start working on creating AI.  Tongue
[-] The following 1 user Likes AbsoluteBeginner's post:
  • litdev
Reply
#84
On the point that the current position is not updated to the server until an animation is fully completed.  This isn't actually true, it is updated regularly (so that the Observer and other multi-player systems can see each other's movement).  Of course you can only be sure you have the final animated position of your robot when it is completely finished animating.  However, new commands can be sent and exist on the server until an animation is completely finished and it is used, but only then so it is generally best to wait fully.
[-] The following 2 users Like litdev's post:
  • AbsoluteBeginner, stevantosic
Reply
#85
Now I want to teach the robot to create a maze map for itself.
Monsters change the value of the "Distance" parameter.
Do you plan to add new objects to the maze that will also be able to change the value of the "Distance" parameter?

Thank you.  Shy
Reply
#86
Currently if there is a monster in view a distance of 1000 is returned.

You can get rid of the monsters by using a maze (set in settings) with none seeded.

I guess at some point it would be good to just report distance and say if it is a wall, monster or other player.  Not sure how to do this with a single distance value as it is now, probably another return data flag?

I don't plan to add anything more, except I may just report the distance to the monster instead of 1000 and find some other way to say it is a monster using a flag for example.  If there is a monster or other player there, then the distance cannot be the distance to the wall behind it since the engine doesn't actually know what is not shown behind another object.

I am open to suggestions on this!

EDIT

I will change so it reports the distance to whatever is there, it will also return a string describing what it saw - this will be the internal object name which will be a wall, enemy or player label.

Hopefully thats it where dist is always the distance to whatever is directly infront of you, and there is also a distLabel string returned saying what it is you see - a little trickier than I thought so hopefully nothing broken - the distance was used to prevent passing through walls and 1000 used for enemies and other players to let us pass throughthem - logic had to change a bit.
[-] The following 1 user Likes litdev's post:
  • AbsoluteBeginner
Reply
#87
(02-18-2025, 05:30 PM)litdev Wrote: ...
I will change so it reports the distance to whatever is there, it will also return a string describing what it saw - this will be the internal object name which will be a wall, enemy or player label.

This will be equivalent to the robot having the ability to recognize images.  Exclamation

This will greatly increase the robot's AI capabilities.  Cool
Reply
#88
Hi, 
This is the code in C# for maze solving based on Sub animateCone in LD3DMazeGame.sb, litdev's  SendWebRequest and AB's post #19 (Hand on The Wall strategy):

Code:
using System;
using System.IO;
using System.Net;
using Newtonsoft.Json;
using Timer = System.Threading.Thread;

public class MazeData
{
    public string name { get; set; }
    public double posX { get; set; }
    public double posZ { get; set; }
    public double angle { get; set; }
    public double dist { get; set; }
    public int move { get; set; }
    public int left { get; set; }
    public int right { get; set; }
    public int cellX { get; set; }
    public int cellZ { get; set; }
    public int dir0 { get; set; }
    public int dir90 { get; set; }
    public int dir180 { get; set; }
    public int dir270 { get; set; }
    public int animate { get; set; }
    public int rotate { get; set; }
    public double forward { get; set; }
    public string game { get; set; }
    public string state { get; set; }
    public string distLabel { get; set; }
}


class Hello
{
    static string SendWebRequest(string url)
    {
        StreamReader streamReader = null;
        WebResponse webResponse = null;
        string result = "";
        try
        {
            WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            WebRequest webRequest = WebRequest.Create(url);
            webResponse = webRequest.GetResponse();
            streamReader = new StreamReader(webResponse.GetResponseStream());
            result = streamReader.ReadToEnd();
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            if (streamReader != null) streamReader.Close();
            if (webResponse != null) webResponse.Close();
        }
        return result;
    }


    static void Main()
    {
        string urlGet = "https://litdev.uk/apps/maze3D/maze3D.php?action=get";
        string urlSet = "https://litdev.uk/apps/maze3D/maze3D.php?action=set";

        int moveDir, dirForward = 1, dirBack, dirRight, dirLeft;
        int[] dirs = new int[4] { 270, 0, 90, 180 }; // 0 1 2 3

        int[] move = new int[4];

        moveDir = dirForward;
        string direction = "";

        while (true)
        {
            string jsonMaze = SendWebRequest(urlGet);
            Console.WriteLine(jsonMaze);

            MazeData objMaze = JsonConvert.DeserializeObject<MazeData>(jsonMaze);
            Console.WriteLine("cellX={0}, cellZ={1}", objMaze.cellX, objMaze.cellZ);

            dirForward = moveDir;

            dirLeft = moveDir - 1;
            if (dirLeft < 0)
                dirLeft += 4;

            dirBack = moveDir - 2;
            if (dirBack < 0)
                dirBack += 4;

            dirRight = moveDir - 3;
            if (dirRight < 0)
                dirRight += 4;


            move[0] = objMaze.dir270;
            move[1] = objMaze.dir0;
            move[2] = objMaze.dir90;
            move[3] = objMaze.dir180;

            if (move[dirLeft] == 1)
            {
                moveDir = dirLeft;
                direction = "dirLeft";
            }
            else if (move[dirForward] == 1)
            {
                moveDir = dirForward;
                direction = "dirForward";
            }
            else if (move[dirRight] == 1)
            {
                moveDir = dirRight;
                direction = "dirRight";
            }
            else
            {
                moveDir = dirBack;
                direction = "dirBack";
            }

            Console.WriteLine("dir = {0}, movDir = {1}", direction, moveDir);
            SendWebRequest(urlSet + "&animate=" + dirs[moveDir].ToString());
            Timer.Sleep(2500);
        }
    }
}

Compiling: 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /r:LitDev.dll maze.cs
Run:
maze

Newtonsoft.Json is located in LitDev.dll.

st
[-] The following 1 user Likes stevantosic's post:
  • litdev
Reply
#89
Works well for me, tried it on the 'Visit all cells' game with default maze and it got 94% before returning to start, it will miss some cells between islands or big open areas, but it does navigate the full maze as we would hope.
Reply
#90
Yes, the problem is "some cells between islands or big open areas ". Hope will be progress regarding it.
Reply


Forum Jump:


Users browsing this thread: 25 Guest(s)