private static Lines GetConsecutiveLines(OmokBoard b, PieceColor color, Point move)
        {
            int horizontal = 1, vertical = 1, mainDiagonal = 1, antiDiagonal = 1;
            int nextX, nextY;

            for (nextX = move.X + 1, nextY = move.Y; nextX < OmokBoard.COLUMNS && b.GetPiece(nextY, nextX) == color; nextX++)
                horizontal++;
            for (nextX = move.X - 1; nextX >= 0 && b.GetPiece(nextY, nextX) == color; nextX--)
                horizontal++;

            for (nextX = move.X, nextY = move.Y + 1; nextY < OmokBoard.ROWS && b.GetPiece(nextY, nextX) == color; nextY++)
                vertical++;
            for (nextX = move.X, nextY = move.Y - 1; nextY >= 0 && b.GetPiece(nextY, nextX) == color; nextY--)
                vertical++;

            for (nextX = move.X + 1, nextY = move.Y + 1; nextX < OmokBoard.COLUMNS && nextY < OmokBoard.ROWS && b.GetPiece(nextY, nextX) == color; nextX++, nextY++)
                mainDiagonal++;
            for (nextX = move.X - 1, nextY = move.Y - 1; nextX >= 0 && nextY >= 0 && b.GetPiece(nextY, nextX) == color; nextX--, nextY--)
                mainDiagonal++;

            for (nextX = move.X + 1, nextY = move.Y - 1; nextX < OmokBoard.COLUMNS && nextY >= 0 && b.GetPiece(nextY, nextX) == color; nextX++, nextY--)
                antiDiagonal++;
            for (nextX = move.X - 1, nextY = move.Y + 1; nextX >= 0 && nextY < OmokBoard.ROWS && b.GetPiece(nextY, nextX) == color; nextX--, nextY++)
                antiDiagonal++;

            return new Lines(horizontal, vertical, mainDiagonal, antiDiagonal);
        }
 internal static MoveResult CanMove(OmokBoard b, Player p, Point move)
 {
     Lines sucessive = GetConsecutiveLines(b, p.Color, move);
     if (sucessive.horizontal > 5 || sucessive.vertical > 5 || sucessive.mainDiagonal > 5 || sucessive.antiDiagonal > 5)
         return MoveResult.OVERLINE;
     if (sucessive.horizontal == 3 && (sucessive.vertical == 3 || sucessive.mainDiagonal == 3 || sucessive.antiDiagonal == 3)
             || sucessive.vertical == 3 && (sucessive.mainDiagonal == 3 || sucessive.antiDiagonal == 3)
             || sucessive.mainDiagonal == 3 && sucessive.antiDiagonal == 3)
         return MoveResult.DOUBLE_THREES;
     return MoveResult.NORMAL;
 }
 internal static MoveResult CurrentStatus(OmokBoard b, Player p, Point move)
 {
     Lines sucessive = GetConsecutiveLines(b, p.Color, move);
     if (sucessive.horizontal == 5 || sucessive.vertical == 5 || sucessive.mainDiagonal == 5 || sucessive.antiDiagonal == 5)
         return MoveResult.FIVE_IN_A_ROW;
     for (int i = 0; i < OmokBoard.ROWS; i++)
         for (int j = 0; j < OmokBoard.COLUMNS; j++)
             if (b.GetPiece(i, j) == PieceColor.EMPTY)
                 return MoveResult.NORMAL;
     return MoveResult.BOARD_FILLED;
 }
 internal OmokPacketHandler(NetworkPlayer p, OmokBoard board)
 {
     this.player = p;
     this.board = board;
 }
Exemple #5
0
 internal void Select(OmokBoard board, int row, int col)
 {
     if (board.GetPiece(row, col) == PieceColor.EMPTY)
     {
         MoveResult allowed = GameLogic.CanMove(board, this, new Point(col, row));
         switch (allowed)
         {
             case MoveResult.NORMAL:
                 board.DrawPiece(row, col, color);
                 MadeMove(row, col);
                 board.NextTurn(new Point(col, row));
                 break;
             case MoveResult.OVERLINE:
                 MessageBox.Show(board, "You may not place a piece there\nsince it will cause you to have\nmore than five pieces in a row.", "Illegal Move", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 break;
             case MoveResult.DOUBLE_THREES:
                 MessageBox.Show(board, "You may not place a piece there\nsince it will cause you to have\ntwo lines of three or more\nconsecutive pieces.", "Illegal Move", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 break;
         }
     }
 }