public ComputerPlayer(string name, Boolean turn, Board gboard, string glevel)
            : base (name, turn)
        {
          
            superMario = new AI(gboard, glevel);

        }
Beispiel #2
0
 public AIBoard(Board gameBoard)
 {
     boardNetwork = new BoardNode[NUM_ROW, NUM_COL];
     possibleMoves = new List<BoardNode>();
     CreateBoardNodes(gameBoard);
     ConnectBoardNodes();
     GeneratePossibleMoves();
 }
Beispiel #3
0
        // The Game window is loaded with Player One and Player Two username, stones, game mode, and who has the first move.
        public Game(int playMode, String player1,  Boolean player1turn, BitmapImage p1gstone, String player2, Boolean player2turn, BitmapImage  p2gstone, String gLevel )
        {

            InitializeComponent();
            
            gameCounter = 36;
            gamePlayers = new Player[2];
            gameBoard = new Board();
            gameLevel = gLevel;
            GameOver = false;
            gameMode = playMode;
            playerOneGameStone = p1gstone;
            playerTwoGameStone = p2gstone;
            playerOneId = player1;
            playerTwoId = player2;
            Label_PlayerOneName.Content = player1;
            Label_PlayerTwoName.Content = player2;
            player2Image.Source = p2gstone;
            player1Image.Source = p1gstone;
            soundON = false;


         

            if (playMode == 1)
            {
                isPlayerOneGame = true;
          
                gamePlayers[0] = new Player (player1, player1turn);

                AI_mario=  new ComputerPlayer(player2, player2turn, gameBoard, gameLevel);

                gamePlayers[1] = AI_mario;

                if (player2turn)
                {
                   

                    Button_1x1.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
                }

            }
            else if (playMode == 2)
            {

                isPlayerOneGame = false;
           

                gamePlayers[0] = new Player (player1, player1turn);
                gamePlayers[1] = new Player (player2, player2turn);
            }


        }
Beispiel #4
0
        public AI(Board gboard, string glevel)
        {
            gameBoard = gboard;
            gameLevel = glevel;

            if (glevel.Equals("Easy"))
            { isEasy = true; isMedium = false; isHard = false; }
            else if (glevel.Equals("Medium"))
            { isEasy = false; isMedium = true; isHard = false; }
            else if (glevel.Equals("Hard"))
            { isEasy = false; isMedium = false; isHard = true; }
        }
Beispiel #5
0
/*
 *This module checks the board and returns the cell number for computer player to click.  
1.	Check the current status of the game board.
2.	Calculate the change in score for offensive by checking computer player score.
3.	Calculate the change in score for defensive by checking human player score.
4.	Return the location if offensive or defensive is better.
5.	If both score are same then use look ahead strategy.
6.	Circular to check any score can be made with priority assigned.
7.	Second block to stop any consecutive third moves.
8.	Use down right, up right, down left, up left to block ahead moves.

*/
private int[] mediumMove()
{
    int[] cell = { -1, -1 };

    int next_x_offensive = -1;
    int next_y_offensive = -1;
    int next_x_defensive = -1;
    int next_y_defensive = -1;


    Board testBoard = new Board();

    testBoard.setGameMatrix(gameBoard.getGameMatrix());

    // offensive 

    testBoard.setPlayerTwoScore(gameBoard.getPlayerTwoScore());
    int trialScore = testBoard.getPlayerTwoScore();
    int oldScore = testBoard.getPlayerTwoScore();



    for (int i = 0; i < 6; i++)
    {
        for (int j = 0; j < 6; j++)
        {

            if (testBoard.isFree(i, j))
            {
                testBoard.updateBoard(i, j, 2);

                trialScore = testBoard.getPlayerTwoScore();

                if (trialScore > oldScore)
                {
                    next_x_offensive = i;
                    next_y_offensive = j;
                    j = 7;
                    i = 7;
                    Console.WriteLine("this is - OFFENSIVE ");
                    Console.WriteLine("--------------------");
                }
                else
                {
                    testBoard.deleteLastMove(i, j);
                }

            }
        }
    }

    //  defensive 

    testBoard.setPlayerOneScore(gameBoard.getPlayerOneScore());
    trialScore = testBoard.getPlayerOneScore();
    oldScore = testBoard.getPlayerOneScore();



    for (int i = 0; i < 6; i++)
    {
        for (int j = 0; j < 6; j++)
        {
            if (testBoard.isFree(i, j))
            {
                testBoard.updateBoard(i, j, 1);

                trialScore = testBoard.getPlayerOneScore();

                if (trialScore > oldScore)
                {
                    next_x_defensive = i;
                    next_y_defensive = j;
                    j = 7;
                    i = 7;
                    Console.WriteLine("this is - DEFENSIVE ");
                    Console.WriteLine("--------------------");
                }
                else
                {
                    testBoard.deleteLastMove(i, j);
                }
            }

        }
    }



    if (next_x_offensive == -1 && next_x_defensive != -1)
    {
        cell[0] = next_x_defensive;
        cell[1] = next_y_defensive;
    }
    else if (next_x_offensive != -1 && next_x_defensive == -1)
    {
        cell[0] = next_x_offensive;
        cell[1] = next_y_offensive;
    }
    else if (next_x_offensive != -1 && next_x_defensive != -1)
    {
        cell[0] = next_x_offensive;
        cell[1] = next_y_offensive;
    }

    else if (next_x_offensive == -1 && next_x_defensive == -1)
    {
        int[] lastMove = gameBoard.getLastMove();

        int lastMove_x = lastMove[0];
        int lastMove_y = lastMove[1];

        bool cellChanged = false;


        if (lastMove_x == -1 && lastMove_y == -1)
        {
            cell = easyMove();

        }
        else
        {






            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {

                    if (lastMove_x == i && lastMove_y == j)
                    {
                        Console.WriteLine("this is -  TACKLE  @ " + i + j);
                        Console.WriteLine("--------------------");
                        // circle
                        if (j <= 4 && j >= 1 && i <= 4 && i >= 1)
                        {
                            // two consecutive move block

                            if(gameBoard.getGameMatrix()[i,j]==1 && gameBoard.getGameMatrix()[i-1, j] == 1)
                            {

                                if (gameBoard.isFree(i + 1, j))
                                {
                                    cell[0] = i + 1;
                                    cell[1] = j;
                                    cellChanged = true;
                                }

                            }
                            else if (gameBoard.getGameMatrix()[i, j] == 1 && gameBoard.getGameMatrix()[i + 1, j] == 1)
                            {
                                if (gameBoard.isFree(i - 1, j))
                                {
                                    cell[0] = i - 1;
                                    cell[1] = j;
                                    cellChanged = true;
                                }
                            }
                            else if (gameBoard.getGameMatrix()[i, j] == 1 && gameBoard.getGameMatrix()[i , j-1] == 1)
                            {

                                if (gameBoard.isFree(i, j+1))
                                {
                                    cell[0] = i ;
                                    cell[1] = j+1;
                                    cellChanged = true;
                                }


                            }
                            else if (gameBoard.getGameMatrix()[i, j] == 1 && gameBoard.getGameMatrix()[i , j+1] == 1)
                            {

                                if (gameBoard.isFree(i, j - 1))
                                {
                                    cell[0] = i;
                                    cell[1] = j - 1;
                                    cellChanged = true;
                                }

                            }
                            else
                            {
                                cell = easyMove();
                            }

                            if (!cellChanged)
                            {

                                if (gameBoard.isFree(i - 1, j))

                                {
                                    cell[0] = i - 1;
                                    cell[1] = j;
                                }

                                else if (gameBoard.isFree(i + 1, j))

                                {
                                    cell[0] = i + 1;
                                    cell[1] = j;
                                }

                                else if (gameBoard.isFree(i, j - 1))
                                {
                                    cell[0] = i;
                                    cell[1] = j - 1;
                                }

                                else if (gameBoard.isFree(i, j + 1))

                                {
                                    cell[0] = i;
                                    cell[1] = j + 1;
                                }


                                else if (gameBoard.isFree(i - 1, j - 1))
                                {
                                    cell[0] = i - 1;
                                    cell[1] = j - 1;
                                }

                                else if (gameBoard.isFree(i + 1, j - 1))

                                {
                                    cell[0] = i + 1;
                                    cell[1] = j - 1;
                                }

                                else if (gameBoard.isFree(i + 1, j + 1))

                                {
                                    cell[0] = i + 1;
                                    cell[1] = j + 1;
                                }

                                else if (gameBoard.isFree(i - 1, j + 1))

                                {
                                    cell[0] = i - 1;
                                    cell[1] = j + 1;
                                }
                                else
                                {
                                    cell = easyMove();
                                }

                            }
                        } 
                        // down right
                        else if (i >= 0 && i <= 4 && j >= 0 && j <= 4)
                        {
                            if (gameBoard.isFree(i, j + 1))
                            {
                                cell[0] = i;
                                cell[1] = j + 1;
                            }
                            else if (gameBoard.isFree(i + 1, j + 1))
                            {
                                cell[0] = i + 1;
                                cell[1] = j + 1;
                            }
                            else if (gameBoard.isFree(i + 1, j))
                            {
                                cell[0] = i + 1;
                                cell[1] = j;
                            }
                            else
                            {
                                cell = easyMove();
                            }

                        }

                        //up right
                        else if (i <= 5 && i >= 1 && j >= 0 && j <= 4)
                        {
                            if (gameBoard.isFree(i, j + 1))
                            {
                                cell[0] = i;
                                cell[1] = j + 1;
                            }
                            else if (gameBoard.isFree(i - 1, j + 1))
                            {
                                cell[0] = i - 1;
                                cell[1] = j + 1;
                            }
                            else if (gameBoard.isFree(i - 1, j))
                            {
                                cell[0] = i - 1;
                                cell[1] = j;
                            }
                            else
                            {
                                cell = easyMove();
                            }

                        }
                        //down left
                        else if (j <= 5 && j >= 1 && i >= 0 && i <= 4)
                        {
                            if (gameBoard.isFree(i, j - 1))
                            {
                                cell[0] = i;
                                cell[1] = j - 1;
                            }
                            else if (gameBoard.isFree(i + 1, j - 1))
                            {
                                cell[0] = i + 1;
                                cell[1] = j - 1;
                            }
                            else if (gameBoard.isFree(i + 1, j))
                            {
                                cell[0] = i + 1;
                                cell[1] = j;
                            }
                            else
                            {
                                cell = easyMove();
                            }

                        }

                        // up left
                        else if (j <= 5 && j >= 1 && i <= 5 && i >= 1)
                        {
                            if (gameBoard.isFree(i, j - 1))
                            {
                                cell[0] = i;
                                cell[1] = j - 1;
                            }
                            else if (gameBoard.isFree(i - 1, j - 1))
                            {
                                cell[0] = i - 1;
                                cell[1] = j - 1;
                            }
                            else if (gameBoard.isFree(i - 1, j))
                            {
                                cell[0] = i - 1;
                                cell[1] = j;
                            }
                            else
                            {
                                cell = easyMove();
                            }


                        }



                    }


                }

            }


        }
    }




    return cell;
}
Beispiel #6
0
 /********************************************************************************
 * Creates board network nodes reflecting the gameBoard passed in as a parameter *
 ********************************************************************************/
 void CreateBoardNodes(Board gameBoard)
 {
     int[,] boardMatrix = gameBoard.getGameMatrix();
     for (int r = 0; r < NUM_ROW; r++)
     {
         for (int c = 0; c < NUM_COL; c++)
         {
             boardNetwork[r, c] = new BoardNode(boardMatrix[r, c], r, c);
         }
     }
 }
Beispiel #7
0
        public Board(Board board)
        {
            gameBoard = board.getGameMatrix();
            calculateScore();

        }