Пример #1
0
        /// <summary>
        /// Make all possible moves and chooses the once which guarantees the max profit
        /// </summary>
        private Tuple <double, MoveInformation> MakeAnalyzingMoves(MoveInformation moveInformation, int depth,
                                                                   PlayerType playerType, List <Cell> currentPlayerArmyCells,
                                                                   List <Cell> otherPlayerArmyCells)
        {
            var memorizedFrom = new ItemAndPosition(GetItemByPosition(moveInformation.From), moveInformation.From); // memorizing position
            var memorizedTo   = new ItemAndPosition(GetItemByPosition(moveInformation.To), moveInformation.To);

            MakeMove(moveInformation.From, moveInformation.To);
            ChangeArmyListAfterMoving(currentPlayerArmyCells, playerType, moveInformation); // changing list of armies after move
            ChangeArmyListAfterMoving(otherPlayerArmyCells, GetOppositePlayerType(playerType), moveInformation);

            Tuple <double, MoveInformation> result;

            if (PlayerArmiesWereKilled(currentPlayerArmyCells) || PlayerArmiesWereKilled(otherPlayerArmyCells)) // If game ends because of armies of one player were killed
            {
                result = OnOnceArmiesKilled(currentPlayerArmyCells, otherPlayerArmyCells, playerType);
            }
            else
            {
                result = AnalyzeStrategy(GetOppositePlayerType(playerType), false, // Just analyzing the move profit
                                         depth - 1, otherPlayerArmyCells,
                                         currentPlayerArmyCells);
            }

            CancelMove(memorizedFrom, memorizedTo);
            ChangeArmyListAfterCancellingMove(currentPlayerArmyCells, otherPlayerArmyCells, // Changing list of armies after cancelling move
                                              playerType, moveInformation, memorizedFrom, memorizedTo);

            return(result);
        }
Пример #2
0
        /// <summary>
        /// After cancelling move in game simulation all armies should return to their cells and list of
        /// armies should be updated
        /// </summary>
        private void ChangeArmyListAfterCancellingMove(List <Cell> currentPlayerArmyCells,
                                                       List <Cell> otherPlayerArmyCells, PlayerType playerType, MoveInformation move,
                                                       ItemAndPosition memorizedFrom, ItemAndPosition memorizedTo)
        {
            currentPlayerArmyCells.Remove(move.To);
            otherPlayerArmyCells.Remove(move.To);

            if (memorizedFrom.Item?.Army != null)
            {
                AddCellToArmyCellsList(currentPlayerArmyCells, otherPlayerArmyCells, playerType,
                                       memorizedFrom.Item.Army.PlayerType, move.From);
            }

            if (memorizedTo.Item?.Army != null)
            {
                AddCellToArmyCellsList(currentPlayerArmyCells, otherPlayerArmyCells, playerType,
                                       memorizedTo.Item.Army.PlayerType, move.To);
            }
        }
Пример #3
0
 /// <summary>
 /// Cancels move by setting items back
 /// </summary>
 private void CancelMove(ItemAndPosition from, ItemAndPosition to)
 {
     from.Item.Army.SetActive();
     boardStorage.SetItem(from.Cell, from.Item);
     boardStorage.SetItem(to.Cell, to.Item);
 }