   How to make robots in a 10 x 10 array "see" each other
  I am trying to write a simple "Robot" simulation in a C# Windows Form.I have a "World" object which hosts a 10 x 10 array of "Robot" objects.Can someone make recommendations on how to code my "Robots" so they can look around their "World" and identify other objects?The "Robot" would be able to look at ALL adjacent squares and identify what is in the square. For now, the square is either empty or has an identical "Robot".I also want the "Robot" to be able to move around in the world according to a set of rules.  For now all I can think of is:1)  Go up until you cannot go up any more2)  Go right one square.  3)  If you cannot go right then go left one square.4)  Go down until you cannot go down anymore.  5)  Go right one square.  If you cannot go right then go left.6)  Go to step 1I can work on this, but I need advice on where and how to implement this.I have all of these "Robots" in a 10 x 10 array but I don't know how to make them "aware" of each other and what is around them.  I want to use OOP, and I want to write the code in a very understandable and intuitive fashion (as much as I can)[source lange="cpp"]using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace TestAI{/// &lt;summary&gt;/// Summary description for Form1./// &lt;/summary&gt;public class Form1 : System.Windows.Forms.Form{private System.Windows.Forms.TextBox textBoxWorld;private System.Windows.Forms.PictureBox pictureBoxWorld;private System.Windows.Forms.Button button1;private World _new_world = new World();/// &lt;summary&gt;/// Required designer variable./// &lt;/summary&gt;private System.ComponentModel.Container components = null;public Form1(){//// Required for Windows Form Designer support//InitializeComponent();//// TODO: Add any constructor code after InitializeComponent call//}/// &lt;summary&gt;/// Clean up any resources being used./// &lt;/summary&gt;protected override void Dispose( bool disposing ){if( disposing ){if (components != null) {components.Dispose();}}base.Dispose( disposing );}#region Windows Form Designer generated code/// &lt;summary&gt;/// Required method for Designer support - do not modify/// the contents of this method with the code editor./// &lt;/summary&gt;private void InitializeComponent(){this.textBoxWorld = new System.Windows.Forms.TextBox();this.pictureBoxWorld = new System.Windows.Forms.PictureBox();this.button1 = new System.Windows.Forms.Button();this.SuspendLayout();// // textBoxWorld// this.textBoxWorld.Location = new System.Drawing.Point(16, 32);this.textBoxWorld.Multiline = true;this.textBoxWorld.Name = "textBoxWorld";this.textBoxWorld.Size = new System.Drawing.Size(384, 400);this.textBoxWorld.TabIndex = 0;this.textBoxWorld.Text = "";// // pictureBoxWorld// this.pictureBoxWorld.Borderstyle = System.Windows.Forms.Borderstyle.FixedSingle;this.pictureBoxWorld.Location = new System.Drawing.Point(472, 40);this.pictureBoxWorld.Name = "pictureBoxWorld";this.pictureBoxWorld.Size = new System.Drawing.Size(408, 392);this.pictureBoxWorld.TabIndex = 1;this.pictureBoxWorld.TabStop = false;this.pictureBoxWorld.Click += new System.EventHandler(this.pictureBoxWorld_Click);this.pictureBoxWorld.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBoxWorld_Paint);// // button1// this.button1.Location = new System.Drawing.Point(720, 472);this.button1.Name = "button1";this.button1.TabIndex = 2;this.button1.Text = "button1";this.button1.Click += new System.EventHandler(this.button1_Click);// // Form1// this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);this.ClientSize = new System.Drawing.Size(960, 606);this.Controls.Add(this.button1);this.Controls.Add(this.pictureBoxWorld);this.Controls.Add(this.textBoxWorld);this.Name = "Form1";this.Text = "Form1";this.Load += new System.EventHandler(this.Form1_Load);this.ResumeLayout(false);}#endregion/// &lt;summary&gt;/// The main entry point for the application./// &lt;/summary&gt;[STAThread]static void Main() {Application.Run(new Form1());}private void pictureBoxWorld_Click(object sender, System.EventArgs e){}private void Form1_Load(object sender, System.EventArgs e){_new_world.CreateRobots();}private void pictureBoxWorld_Paint(object sender, System.Windows.Forms.PaintEventArgs e){try{_new_world.DisplayWorld(e.Graphics);}catch(Exception ee){System.Diagnostics.Debug.WriteLine(ee.ToString());}}private void button1_Click(object sender, System.EventArgs e){this.pictureBoxWorld.Refresh();}}public class World{private const int _MIN_ROW = 0;private const int _MAX_ROW = 9;private const int _MIN_COL = 0;private const int _MAX_COL = 9;public Graphics world_graphics;public Image img;private Robot[,] robo = new Robot[10,10];public World(){}public void CreateRobots(){for(int i=0;i&lt;10;i++){for(int j=0;j&lt;10;j++){robo[i,j] = new Robot();robo[i,j].RobotStatus = Image.FromFile("images\\none.bmp");robo[i,j].Name = "";}}robo[0,0].Name = "Tom";robo[0,0].RobotStatus = Image.FromFile("images\\searcher.bmp");robo[9,9].Name = "Bob";robo[9,9].RobotStatus = Image.FromFile("images\\searcher.bmp");}public void DisplayWorld(Graphics gr){for(int x=0;x&lt;10;x++){for(int y=0;y&lt;10;y++){gr.DrawImage(robo[x,y].RobotStatus,x*32,y*32);}}}}public class Robot{private Image _robotStatus;private const string _IMAGE_DIR = "images";private const string _DIR_DELIMETER = "\\";private const string _FULL_IMAGE_DIR = _IMAGE_DIR + _DIR_DELIMETER;private const string _ATTACKER = "attacker.bmp";private const string _SEARCHER = "searcher.bmp";private const string _NONE = "none.bmp";private string _name;private int _row;private int _col;public Image RobotStatus{get{ return _robotStatus;}set{_robotStatus = value;}}public int Row{get{ return _row;}set{_row = value;}}public string Name{get{ return _name;}set{_name = value;}}public Robot(){}}}
  A very interesting idea. Something i might have a go at and port to a 3D API later.To be honest mate you seem to have covered everything. I sugest you just go for it. It might be a better option to do it in 2D in OpenGL or Direct3D.Dave   ;  You say the robots can see all adjacent squares, so a robot at [5,5] can see:[4,5], [6,5], [5,6] and [5,4] right? Can they also see [4,4], [6,6], [4,6] and [6,4]? If it's the former couldn't you just have 4 boolean variables:RobotRight, RobotLeft, RobotUp and RobotDown and each time some robot move you update them like this:RobotLeft = (RobotGrid[x-1,y] == ROBOT);RobotRight = (RobotGrid[x+1,y] == ROBOT);RobotUp = (RobotGrid[x,y+1] == ROBOT);RobotDown = (RobotGrid[x,y-1] == ROBOT);If it is the latter you could just add RobotLeftUp, RobotLeftDown, RobotRightUp and RobotRightLeft.Your movement will be pretty weird if it follows your rules imagine this:543x21  x 12345Where x is robots and numbers is just to make it easier to see the robots position.First both robot would go up:5x x4321   12345Them right:5 x x4321   12345Then down:54321 x x 12345And right again:54321  x x 12345The leftmost x would now only be in column 4 and 5(since once it enters 4th row again it can go right, and wont go left until it is in fifth row). In a couple of steps the rightmost x would also be stuck in column 4 and 5.   ;  You could always choose a target robot for each robot, and then move towards that robot. Then, every once and a while have them change targets so they dont end up orbiting each other.   ;  Could you not just use vectors applied to the array position as a "beam" of vision?   ;Quote:Original post by XpyderCould you not just use vectors applied to the array position as a "beam" of vision?My question is how do I do this in the source code?What does my code look like such that my Robot can "look at" the square above it?  How does it know there is a square above it?Should I store the Row and Column position INSIDE each Robot?I am not sure if I am phrasing my question right.   ;  You need to be able to:- For a given cell, determine if there is a Robot in it (we don't care which one). We can accomplish this by representing the cells as an array of some object which includes a Robot reference.- For a given robot, determine which cell it is in. The Robot could track this information, but it's really the World which cares. One possibility is to search the World each time and find the Robot which is equal to the one we care about; this will be slow, however. Realistically, it is more practical to track the information. All we do then is have the Robot ask the World if anything can be seen from its current location, and if the path is clear, update its position.One problem you may have is that you do not separate the concept of a location in the map from the concept of the robot which may or may not occupy that location. You don't have a good way of checking the robot status, because every cell uses its own copy of the Image - a bad idea anyway, because it wastes huge amounts of memory. Even if we do not bother creating the separation, you will want to have one static instance of each Image, and make each Robot instance refer to one of them. Then you can simply check whether a cell is empty by comparing its 'status Image' reference to the 'blank Image' reference.