Beispiel #1
0
        public IEnumerable <ListHex> GetPossibleMoves(List <ListHex> path, List <ListHex> myPath, PlayerType player, ListMap map)
        {
            var opponent         = player == PlayerType.Blue ? PlayerType.Red : PlayerType.Blue;
            var lastOpponentMove = opponent == PlayerType.Blue ? map.LastBlueMove : map.LastRedMove;

            var possibleMoves = new HashSet <ListHex>();

            if (lastOpponentMove != null)
            {
                foreach (var move in lastOpponentMove.Neighbours)
                {
                    var hex = map.HexAt(move.ToTuple());
                    if (hex != null && hex.Owner == PlayerType.White)
                    {
                        hex.Priority += 3;
                        possibleMoves.Add(hex);
                    }
                }
            }

            foreach (var move in path)
            {
                var hex = map.HexAt(move.ToTuple());
                if (hex != null && hex.Owner == PlayerType.White)
                {
                    hex.Priority += 2;
                    possibleMoves.Add(hex);
                }
            }

            foreach (var move in myPath)
            {
                var hex = map.HexAt(move.ToTuple());
                if (hex != null && hex.Owner == PlayerType.White)
                {
                    hex.Priority++;
                    possibleMoves.Add(hex);
                }
            }

            //foreach (var move in map.Board)
            //{
            //    if (move.Owner == PlayerType.White)
            //    {
            //        possibleMoves.Add(move);
            //    }
            //}

            var possibleMovesList = possibleMoves
                                    .OrderByDescending(x => x.Priority)
                                    .ThenBy(x => x.DistanceTo(lastOpponentMove))
                                    .ThenBy(x => x.RandomValue).Where(x => x.Owner == PlayerType.White).ToList();


            //Console.Write("Possible moves: ");
            //possibleMovesList.ForEach(x => Console.Write(x + " "));
            //Console.WriteLine("");

            return(possibleMovesList);
        }