public abstract Action Move(AntVision antVision);
public override Action Move(AntVision antVision) //TODO add in weighted randomisation for movement (weight based on tiles next to it) so like a goal is a higher weight. { /* * antVision is 3*3 bitmap. * tile setup is as follows (numbers refer to array index): * _____ |0 3 6| |1 4 7| //4 is always walkable (unless code is very broken) |2_5_8| * */ FloorTile.TileType best_tile = FloorTile.TileType.Blank; List <bool> walkable_tiles_list = new List <bool>(); bool[] walkable_tiles; int random_int = 0; for (int x_count = 0; x_count < 3; x_count++) //TODO change this... //what to? { for (int y_count = 0; y_count < 3; y_count++) { walkable_tiles_list.Add(IsTileWalkable(antVision._antVision[x_count, y_count])); } } //walkable_tiles_list.Add(true); //here to allow the ant to stay still (and to do things with the tile it is standing on) walkable_tiles = walkable_tiles_list.ToArray(); //TODO redo this function to allow for preference of direction. do { random_int = _random.Next(walkable_tiles.Length); } while (random_int % 2 == 0 || walkable_tiles_list[random_int] == false); switch (random_int) { case (1): { _location.X += -1; break; } case (3): { _location.Y += -1; break; } case (5): { _location.Y += 1; break; } case (7): { _location.X += 1; break; } } if (carrying_gold) { if (antVision._antVision[1, 1] == FloorTile.TileType.Home) { //-TODO pass ant_vision as array of FloorTile. Pass by reference to allow for ant editing tiles. //TODO increment home tile. carrying_gold = false; return(Action.None); } return(Action.DropPheremone); } else if (antVision._antVision[1, 1] == FloorTile.TileType.Goal) { carrying_gold = true; } return(Action.None); }
public void Step(int steps = 1) { for (int count = 0; count < steps; count++) { _gameBoard.Step(1); //TODO use events foreach (Ant ant in _ants) //TODO Events? { Point initial_location = ant._location; //TODO this doesn't show pheremones to the ants. //TODO set all tiles here so if it's a null then we can sort it. FloorTile.TileType zerozero = FloorTile.TileType.Null; FloorTile.TileType zeroone = FloorTile.TileType.Null; FloorTile.TileType zerotwo = FloorTile.TileType.Null; FloorTile.TileType onezero = FloorTile.TileType.Null; FloorTile.TileType oneone = FloorTile.TileType.Null; FloorTile.TileType onetwo = FloorTile.TileType.Null; FloorTile.TileType twozero = FloorTile.TileType.Null; FloorTile.TileType twoone = FloorTile.TileType.Null; FloorTile.TileType twotwo = FloorTile.TileType.Null; List <Pheremone> phzerozero = new List <Pheremone>(); List <Pheremone> phzeroone = new List <Pheremone>(); List <Pheremone> phzerotwo = new List <Pheremone>(); List <Pheremone> phonezero = new List <Pheremone>(); List <Pheremone> phoneone = new List <Pheremone>(); List <Pheremone> phonetwo = new List <Pheremone>(); List <Pheremone> phtwozero = new List <Pheremone>(); List <Pheremone> phtwoone = new List <Pheremone>(); List <Pheremone> phtwotwo = new List <Pheremone>(); try { zerozero = _gameBoard.GetTileAtLocation(initial_location.X - 1, initial_location.Y - 1).GetTileType(); phzerozero = _gameBoard.GetPheremonesAtLocation(initial_location.X - 1, initial_location.Y - 1); } catch (Exception e) { } try { zeroone = _gameBoard.GetTileAtLocation(initial_location.X - 1, initial_location.Y).GetTileType(); phzeroone = _gameBoard.GetPheremonesAtLocation(initial_location.X - 1, initial_location.Y); } catch (Exception e) { } try { zerotwo = _gameBoard.GetTileAtLocation(initial_location.X - 1, initial_location.Y + 1).GetTileType(); phzerotwo = _gameBoard.GetPheremonesAtLocation(initial_location.X - 1, initial_location.Y + 1); } catch (Exception e) { } try { onezero = _gameBoard.GetTileAtLocation(initial_location.X, initial_location.Y - 1).GetTileType(); phonezero = _gameBoard.GetPheremonesAtLocation(initial_location.X, initial_location.Y - 1); } catch (Exception e) { } try { oneone = _gameBoard.GetTileAtLocation(initial_location.X, initial_location.Y).GetTileType(); phoneone = _gameBoard.GetPheremonesAtLocation(initial_location.X, initial_location.Y); } catch (Exception e) { } try { onetwo = _gameBoard.GetTileAtLocation(initial_location.X, initial_location.Y + 1).GetTileType(); phonetwo = _gameBoard.GetPheremonesAtLocation(initial_location.X, initial_location.Y + 1); } catch (Exception e) { } try { twozero = _gameBoard.GetTileAtLocation(initial_location.X + 1, initial_location.Y - 1).GetTileType(); phtwozero = _gameBoard.GetPheremonesAtLocation(initial_location.X + 1, initial_location.Y - 1); } catch (Exception e) { } try { twoone = _gameBoard.GetTileAtLocation(initial_location.X + 1, initial_location.Y).GetTileType(); phtwoone = _gameBoard.GetPheremonesAtLocation(initial_location.X + 1, initial_location.Y); } catch (Exception e) { } try { twotwo = _gameBoard.GetTileAtLocation(initial_location.X + 1, initial_location.Y + 1).GetTileType(); phtwotwo = _gameBoard.GetPheremonesAtLocation(initial_location.X + 1, initial_location.Y + 1); } catch (Exception e) { } AntVision ant_vision = new AntVision( //TODO add pheremone detection here... zerozero, onezero, twozero, zeroone, oneone, twoone, zerotwo, onetwo, twotwo, phzerozero, phonezero, phtwozero, phzeroone, phoneone, phtwoone, phzerotwo, phonetwo, phtwotwo ); Ant.Action ant_action = ant.Move(ant_vision); switch (ant_action) //REMEMBER all actions are done to PREVIOUS tile { default: { break; } case (Ant.Action.DropPheremone): { Pheremone ph = new Pheremone(this, initial_location, 255, 0.5); _gameBoard.addPheremone(ph); break; } } } } OnBoardStep(new GameBoardSteppedEventArgs(DrawWholeGameBoard(_gameBoard))); }