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:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Small Basic AI Championship
#21
AbsoluteBeginner,

Sure you should use whatever communication method you prefer.  The general difficulty with files is performance and synchronicity - reading and writing files is generally a bit slow and you have to sure the file written by one program ends before another reads it.  Synronicity will be hard with files and if there is a delay, then for a game with moving bits the different programs will probably get out of sync.  There is plently of chance for errors and will be slow.  Somehow you really want an event fired when there is something there to read, which is exactly what the LDServer/LDClient stuff does.

You can always change to LDServer methods later, but they are pretty easy to use really, just connect client using connection string (IP) created by server, then send messages from clients (like keys pressed) and the other clients get it as an event message arived.

Do play with these a little before deciding, below is a very simple server client test code:  Save them somewhere, compile them both, then run server followed by several clients.

Sever
Code:
connect = LDServer.Start("True")
File.WriteLine(Program.Directory+"\ConnectIP.txt",1,connect)
TextWindow.Title = "Server"
LDServer.AutoMessages = "True"

While ("True")
  Program.Delay(10)
EndWhile

Client
Code:
connect = File.ReadLine(Program.Directory+"\ConnectIP.txt",1)
LDClient.ServerMessage = OnServerMessage
LDClient.Connect(connect,"True")

button = Controls.AddButton("Press me",10,40)
Controls.ButtonClicked = OnButtonClicked
textBox = Controls.AddTextBox(10,10)
Controls.SetSize(textBox,200,20)

While ("True")
  If (message <> "") Then
    If (Text.EndsWith(message,"CONNECTED")) Then 'Initial connection established
      GraphicsWindow.Title = LDClient.Name
    Else
      Controls.SetTextBoxText(textBox,message) 'Message received
    EndIf
    message = "" 'Wait for another message
  EndIf
  Program.Delay(10)
EndWhile

Sub OnServerMessage
  message = LDClient.LastServerMessage 'Message received
EndSub

Sub OnButtonClicked
  LDClient.SendMessage("Hello") 'Send a message
EndSub
[-] The following 3 users Like litdev's post:
  • AbsoluteBeginner, stevantosic, z-s
Reply
#22
LitDev,

Trying your above code by running the .exes I get" I run server first then client.

LDClient.Connect : Index was outside the bounds of the array.

This is shown by the server.

JR
Reply
#23
JR,

I assume you did save the files somewhere first so that Program.Directory works in a local folder.

You get this error running the client when the localhost IP is not set correctly.

What is set in the "ConnectIP.txt" file written by the server program, it should be something like 192.168.0.118:100, the 0.118 will be different (your local/private IP address), but the rest probably the same 192.168.x.x:100.

Check this first...

PS One further thought - make sure the server program is still running when you start the client programs, that is why we run/compile them first, then run the exes from working folder (server then clients).

Also there may be an os confirmation popup first time server is run.
[-] The following 2 users Like litdev's post:
  • stevantosic, z-s
Reply
#24
LitDev,

It's working now. Don't know why!

JR
[-] The following 1 user Likes jrmrhrb00's post:
  • litdev
Reply
#25
(translated by Google translator)

Hi all.
I'm doing my household chores and I'm thinking what kind of "Nature" should be in the game "Snake" so that the mind of the rabbit and the snake has the opportunity to work?
At this point, I think the rabbit should never see the snake.
The snake always sneaks up on the rabbit without the rabbit noticing. Therefore, the rabbit's intelligence must be enhanced to generate a jumping sequence that makes it as difficult as possible for the snake to bite the rabbit.
The snake has the ability to see the rabbit starting from a certain distance. For example, this distance would be equal to 5 cells.
The snake's intelligence will have to improve so that the snake can end up in the same cell that the rabbit just jumped into.
But, in "Nature" the rabbit will always make his move first. Therefore, the snake will have to make a move to the cell in which the rabbit is most likely to end up, as the snake thinks.
Thus, the snake's mind will study the rabbit's behavior, trying to determine patterns.

This is the picture of the game I now see in my mind.  Smile
[-] The following 2 users Like AbsoluteBeginner's post:
  • litdev, z-s
Reply
#26
How about the game area, fields, walls etc
[-] The following 1 user Likes litdev's post:
  • z-s
Reply
#27
(translated by Google translator)

I was just about to ask what is the most correct way to depict the background and objects?
Is it better to use a background image and sprites, or to draw the shapes and background using drawing techniques?
Which method is faster and more professional?

(It seems to me that using a folder with images is not convenient for distributing the "Nature" program.)
[-] The following 1 user Likes AbsoluteBeginner's post:
  • z-s
Reply
#28
Usually images enhance a game considerably, but in this case for AI it isn't so important, so I would work on the main parts of the game and AI and add images etc later - you can code it so that this is an easy addition.

As an idea for defining the starting scene in a grid for the Rabit and Snake to move in see, NRXL474.000.  This approach is a common way to define game levels.  It can include any number of objects in the game grid scene including the rabit and snake.
[-] The following 1 user Likes litdev's post:
  • z-s
Reply
#29
(translated by Google translator)

I understood your code.
But what did you mean when you wrote "...add images etc later..."?
Does this mean we will use images for sprites?
If we use sprites, how will we distribute them along with the "Nature" program?  Huh
Do we really have to use an archive to download it from the cloud?
Reply
#30
so easily we can make platform game in sb
I am going to start a project of platform game creator
ZS
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)