public Game(Board board) { this.board = board; board.AreaFilled += delegate(object sender, AreaFilledEventArgs e) { Filled += e.FilledArea; if (FilledAreaChanged != null) { FilledAreaChanged (this, getFilledPercents ()); } if (getFilledPercents () >= victoryCondition) { this.End (); if (GameWon != null) { GameWon (this, EventArgs.Empty); } } }; board.PlayerCollision += delegate(object sender, EventArgs e) { Lives -= 1; if (LivesChanged != null) { LivesChanged (this, Lives); } if (Lives == 0) { this.End (); if (GameLost != null) { GameLost (this, EventArgs.Empty); } } }; Running = false; }
public Direction Move(NeighbourMap map, Board board) { if (moveRate > 0 && path.Count > 0 && random.NextDouble () < moveRate) { moveRate *= moveRateStep; } else { if (wait == 0) { sniff (map, board); wait = 30; } else { wait -= 1; } return Direction.None; } return getDirection (map.Current, path.Pop ()); }
public Direction Move(NeighbourMap map, Board board) { if (direction == Direction.None) { turnAnywhere (map); } else { if (rightHand (map) != null && !rightHand (map).Full) { while (front(map) == null || !front (map).Full) { turnLeft (); } } else { turnRight (); } } return direction; }
protected void sniff(NeighbourMap map, Board board) { moveRate = moveRateStep; int[,] record = new int[board.Width, board.Height]; for (int i = 0; i < record.GetLength(0); i++) { for (int j = 0; j < record.GetLength(1); j++) { record [i, j] = -1; } } record [map.Current.X, map.Current.Y] = 0; Queue<Field> queue = new Queue<Field> (); queue.Enqueue (map.Current); Field target = board.Player.BaseField; while (queue.Count > 0) { Field field = queue.Dequeue (); if (field == target) { break; } foreach (Field neighbour in board.GetNeighbours(field)) { if (neighbour.Full && record [neighbour.X, neighbour.Y] == -1) { record [neighbour.X, neighbour.Y] = record [field.X, field.Y] + 1; queue.Enqueue (neighbour); } } } path = new Stack<Field> (); path.Push (target); for (int i = record[target.X, target.Y] - 1; i > 0; i--) { foreach (Field neighbour in board.GetNeighbours(target)) { if (record [neighbour.X, neighbour.Y] == i) { path.Push (neighbour); target = neighbour; break; } } } }
public Direction Move(NeighbourMap map, Board board) { Direction[] directions = new Direction[4]; int peak = 0; if (map.Down != null && map.Down.Full) { directions [peak] = Direction.Down; peak += 1; } if (map.Up != null && map.Up.Full) { directions [peak] = Direction.Up; peak += 1; } if (map.Left != null && map.Left.Full) { directions [peak] = Direction.Left; peak += 1; } if (map.Right != null && map.Right.Full) { directions [peak] = Direction.Right; peak += 1; } return directions [random.Next (0, peak)]; }