protected Move GetMove(string line, Map map) { if (line == null) { Thread.Sleep(10); return null; } line = line.ToLower(); if (!line.StartsWith("o")) return null; var array = line.Split(' '); if (array.Length != 4) return null; int y; int x; if (!int.TryParse(array[1], out y)) return null; if (!int.TryParse(array[2], out x)) return null; if (array[3].Length == 0 || !Moves.ContainsKey(array[3][0])) return null; var move = new Move { LastPosition = new Point(x, y, map.Width, map.Height), NextPosition = new Point(x, y, map.Width, map.Height) + Moves[array[3][0]] }; if (move.IsCorrect(map, PlayerId)) return move; return null; }
public bool IsCorrect(Map map, int playerId) { if (Point.Distance2(LastPosition, NextPosition) > 1) return false; bool isOurAnt = map.ObjectsMap[LastPosition].Type == Cell.CellType.Ant && ((Ant)map.ObjectsMap[LastPosition]).CommandNumber == playerId; bool isMovable = map.OriginalMap[NextPosition].Type != Cell.CellType.Water && map.ObjectsMap[NextPosition].Type != Cell.CellType.Food; return isOurAnt && isMovable; }
public ProcessPlayer(string fileName, Map map, int id, int playerCount) : base(id, playerCount) { _process.StartInfo.UseShellExecute = false; // You can start any process, HelloWorld is a do-nothing example. _process.StartInfo.FileName = fileName; _process.StartInfo.CreateNoWindow = true; _process.StartInfo.RedirectStandardInput = true; _process.StartInfo.RedirectStandardOutput = true; _process.Start(); _process.StandardInput.WriteLine(GetZeroTurnInfo(map)); _process.StandardInput.Flush(); GetMoves(_process.StandardOutput, map); }
protected List<Move> GetMoves(StreamReader input, Map map) { var moves = new List<Move>(); string line; while ((line = input.ReadLine()) == null || !line.StartsWith("go")) { var move = GetMove(line, map); if(move != null) moves.Add(move); } return moves; }
public UnMovableCell(Point point, CellType type, Map originalMap) : base(point, type, originalMap) { }
public UnMovableCell(Point point, Map originalMap) : base(point, originalMap) { }
public Ant(Point point, int command, Map originalMap) : base(point, CellType.Ant, originalMap) { CommandNumber = command; }
public Hill(Point point, int command, Map originalMap) : base(point, CellType.Hill, originalMap) { CommandNumber = command; }
public Food(Point point, Map originalMap) : base(point, CellType.Food, originalMap) { }
public Empty(Point point, Map originalMap) : base(point, CellType.Empty, originalMap) { }
protected string GetZeroTurnInfo(Map map) { return String.Format(@"turn 0 loadtime 3000 turntime 1000 rows {0} cols {1} turns {2} viewradius2 {3} attackradius2 {4} spawnradius2 {5} player_seed 42 ready", map.Height, map.Width, 1000000, map.ViewRadius2, map.AttackRadius2, map.SpawnRadius2); }
private void InitMap() { _map = new Map(File.ReadAllText(_conf["Map"]), _conf.ContainsKey("Symmetric") && bool.Parse(_conf["Symmetric"])); }
public abstract List<Move> PlayMove(List<Cell> visibleCells, int turn, Map map);
public override List<Move> PlayMove(List<Cell> visibleCells, int turn, Map map) { var used = new HashSet<Point>(); var moves = new List<Move>(); foreach (var ant in map.Armies[PlayerId].Ants) { int trys = 4; Move move = null; while ((move == null || used.Contains(move.NextPosition)) && trys > 0) { move = GetMove("o " + ant.Coords.Y + " " + ant.Coords.X + " " + _sides[_rand.Next(4)], map); trys--; } if (move != null && !used.Contains(move.NextPosition)) { moves.Add(move); used.Add(move.NextPosition); } } return moves; }
public override List<Move> PlayMove(List<Cell> visibleCells, int turn, Map map) { return new List<Move>(); }
public Cell(Point point, Map originalMap) : this(point, CellType.Unseen, originalMap) { }
public Cell(Point point, CellType type, Map originalMap) { Coords = point; Type = type; OriginalMap = originalMap; }
public override List<Move> PlayMove(List<Cell> visibleCells, int turn, Map map) { _process.StandardInput.WriteLine(GetVisibleMapDesc(visibleCells, turn)); _process.StandardInput.Flush(); return GetMoves(_process.StandardOutput, map); }