예제 #1
0
 private bool WinInThisMove(List <Line> lines, BoardCell type, out Cell move)
 {
     move = null;
     foreach (var line in lines)
     {
         var next = line.GetTwoNextCells(board);
         var res1 = CanDoWinMove(lines, next.Item1, type);
         if (res1.Found)
         {
             move = res1.Move;
             return(true);
         }
         var res2 = CanDoWinMove(lines, next.Item2, type);
         if (res2.Found)
         {
             move = res2.Move;
             return(true);
         }
     }
     return(false);
 }
예제 #2
0
        public int NextSpace(BoardCell[,] board, BoardCell type)
        {
            // redundant check for case of 2
            int space = 0;

            if (CellIsDesiredType(board, Start.X + Direction.X, Start.Y + Direction.Y, BoardCell.None))
            {
                if (CellIsDesiredType(board, Start.X + 2 * Direction.X, Start.Y + 2 * Direction.Y, type))
                {
                    space++;
                }
            }
            if (CellIsDesiredType(board, End.X - Direction.X, End.Y - Direction.Y, BoardCell.None))
            {
                if (CellIsDesiredType(board, End.X - 2 * Direction.X, End.Y - 2 * Direction.Y, type))
                {
                    space++;
                }
            }
            return(space);
        }
예제 #3
0
        public void SetStep(int i, int j, Player player)
        {
            board[i, j] = new BoardCell(player.image);

            lostCells--;
        }
예제 #4
0
        private MoveResult CanDoWinMove(List <Line> existingLines, Cell proposedMove, BoardCell type)
        {
            if (proposedMove == null)
            {
                return(MoveResult.NotFound);
            }
            board[proposedMove.X, proposedMove.Y] = type;

            var lines = GetLinesByAddingCell(proposedMove, existingLines);

            if (lines.Any(l => l.Count >= 5))
            {
                return(RevertAndReturn(proposedMove, 5));
            }

            board[proposedMove.X, proposedMove.Y] = BoardCell.None;
            return(MoveResult.NotFound);
        }
예제 #5
0
 private int EstimateOtherMove(List <Line> lines, BoardCell type)
 {
     return(SumLines(lines, type == BoardCell.First ? BoardCell.Second : BoardCell.First));
 }
예제 #6
0
        public bool HasFiveInARow(BoardCell boardCell)
        {
            var lines = GetLines(boardCell);

            return(lines.Any(l => l.Count >= 5));
        }
예제 #7
0
 private static bool CellIsDesiredType(BoardCell[,] board, int x, int y, BoardCell type)
 {
     return(x >= 0 && x < 15 && y >= 0 && y < 15 && board[x, y] == type);
 }
예제 #8
0
        public LineType Estimate(BoardCell[,] board, BoardCell type)
        {
            int space;

            switch (Count)
            {
            case 5:
                return(LineType.FiveInRow);

            case 4:
                space = OpenSpace(board);
                if (space == 2)
                {
                    return(LineType.StraightFour);
                }
                if (space == 1)
                {
                    return(LineType.FourInRow);
                }
                return(LineType.DeadFour);

            case 3:
                space = OpenSpace(board);
                var nextThreeSpace = NextSpace(board, type);
                if (nextThreeSpace == 2)
                {
                    return(LineType.StraightFour);
                }
                if (nextThreeSpace == 1)
                {
                    return(LineType.BrokenFourInRow);
                }
                if (space == 2)
                {
                    return(LineType.ThreeInRow);
                }
                if (space == 1)
                {
                    return(LineType.BlokedThree);
                }
                return(LineType.DeadThree);

            case 2:
                space = OpenSpace(board);
                if (space == 2)
                {
                    var nextSpace = NextSpace(board, type);
                    if (nextSpace != 0)
                    {
                        return(LineType.BrokenThree);
                    }
                    return(LineType.TwoInRow);
                }
                if (space == 1)
                {
                    return(LineType.BlockedTwo);
                }
                return(LineType.DeadTwo);

            case 1:
                return(LineType.SingleMark);
            }
            return(LineType.Useless);
        }