Quote:
Original post by Anonymous Poster
I started doing programming like this 30 years ago.
Diections 0-7 0=North 1=NE 2=E etc... (4th quadrant coord system)
INT delta_x[8] = {0,1,1,1,0,-1,-1,-1};
INT delta_y[8] = {-1,-1,0,1,1,1,0,-1};
now you can compare and refer to directions as a positional relation and apply it to movement or a facing, etc...
object.move(INT dir) // move an object along a direction
{
object.x = object.x + delta_x[dir];
object.y = object.y + delta_y[dir];
}
to check if something is in the grid position adjacent to the object ::::
for (dir = 0; dirMAXGRID_X-1) goto OFF_GRID;
if (testxMAXGRID_Y-1) goto OFF_GRID;
if (testy<
Here is what I have so far.
I am not sure I understand the "OFF_GRID" stuff:
using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace TestAI{ public enum Dir { N = 0,NE,E,SE,S,SW,W,NW } public class Robot : Object { public Square _current_square; public Square _min_square; public Square _max_square; int[] delta_row = new int[8] {-1,-1,0,1,1,1,0,-1}; int[] delta_col = new int[8] {0,1,1,1,0,-1,-1,-1}; public Robot(int initial_row, int initial_col, int min_row, int max_row, int min_col, int max_col) { _current_square = new Square(initial_row,initial_col); _min_square = new Square(min_row,min_col); _max_square = new Square(max_row,max_col); _status_icon = Image.FromFile(_ROBOT_IMAGE_PATH); _kind = "robot"; } private ArrayList _squares_visited = new ArrayList(); //CONSTANTS private const string _ROBOT_IMAGE_PATH = "images\\robot.bmp"; //CONSTANTS public string _name; public bool _has_moved = false; public int Row { get{return this._current_square._row;} set { if((value >= this._min_square._row) && (value <= this._max_square._row)) { this._current_square._row = value; } } } public int Col { get{return this._current_square._col;} set { if((value >= this._min_square._col) && (value <= this._max_square._col)) { this._current_square._col = value; } } } public void Move(int Dir) { this._current_square._row += delta_row[Dir]; this._current_square._col += delta_col[Dir]; _has_moved = true; } }}