Difference between revisions of "AS 2019 DisplayNoOfMoves"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "=Setup= You will need to declare 2 new integers at the start of the program, so find: <syntaxhighlight> class Program { const string Space = " "; c...")
 
(Setup)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
=Setup=
 
=Setup=
 
You will need to declare 2 new integers at the start of the program, so find:
 
You will need to declare 2 new integers at the start of the program, so find:
<syntaxhighlight>
+
<syntaxhighlight lang=c#>
 
     class Program
 
     class Program
 
     {
 
     {
Line 15: Line 15:
  
 
You can add:
 
You can add:
<syntaxhighlight>
+
<syntaxhighlight lang=c#>
 
         int amoves = 0;
 
         int amoves = 0;
 
         int bmoves = 0;
 
         int bmoves = 0;
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
Because most of the methods are declared as static you will also need to add static to the variables:
 +
<syntaxhighlight  lang=c#>
 +
        static int amoves = 0;
 +
        static int bmoves = 0;
 +
</syntaxhighlight>
  
 
=Where=
 
=Where=
 
Look in the Game method, you need to find the if statement below:
 
Look in the Game method, you need to find the if statement below:
  
<syntaxhighlight>
+
<syntaxhighlight lang=c#>
 
   if (nextPlayer == "a")
 
   if (nextPlayer == "a")
 
                 {
 
                 {
Line 43: Line 48:
 
This controls player a's turn, it will display the list of possible moves and then check if moves are available. The best place to display the number of moves would be to put a message before it lists the possible moves. See the Console.WriteLine below, you will also need to increment amoves. This is straight after the line to make the actual move:
 
This controls player a's turn, it will display the list of possible moves and then check if moves are available. The best place to display the number of moves would be to put a message before it lists the possible moves. See the Console.WriteLine below, you will also need to increment amoves. This is straight after the line to make the actual move:
  
<syntaxhighlight>
+
<syntaxhighlight lang=c#>
 
   if (nextPlayer == "a")
 
   if (nextPlayer == "a")
 
                 {
 
                 {
Line 55: Line 60:
 
                         nextPlayer = SwapPlayer(nextPlayer);
 
                         nextPlayer = SwapPlayer(nextPlayer);
 
                     }
 
                     }
 +
                    else
 +
                    {
 +
                        gameEnd = true;
 +
                    }
 +
                }
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Now we need to repeat this for player a's turn:
+
Now we need to repeat this for player b's turn, this is controlled by the else section of the above if statement:
  
<syntaxhighlight>
+
<syntaxhighlight lang=c#>
 
   else
 
   else
 
                 {
 
                 {
Line 71: Line 81:
 
                         nextPlayer = SwapPlayer(nextPlayer);
 
                         nextPlayer = SwapPlayer(nextPlayer);
 
                     }
 
                     }
 +
                    else
 +
                    {
 +
                        gameEnd = true;
 +
                    }
 +
                }
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 15:00, 1 April 2019

Setup

You will need to declare 2 new integers at the start of the program, so find:

    class Program
    {
        const string Space = "     ";
        const string Unused = "XXXXX";
        const int BoardSize = 8;
        const int NumberOfPieces = 12;
        const int MaxMoves = 50;
        const int Row = 0;
        const int Column = 1;
        const int Dame = 2;

You can add:

        int amoves = 0;
        int bmoves = 0;

Because most of the methods are declared as static you will also need to add static to the variables:

        static int amoves = 0;
        static int bmoves = 0;

Where

Look in the Game method, you need to find the if statement below:

  if (nextPlayer == "a")
                {
                    ListPossibleMoves(board, A, nextPlayer, listOfMoves);
                    if (!ListEmpty(listOfMoves))
                    {
                        pieceIndex = SelectMove(listOfMoves);
                        MakeMove(board, A, B, listOfMoves, pieceIndex);
                        nextPlayer = SwapPlayer(nextPlayer);
                    }
                    else
                    {
                        gameEnd = true;
                    }
                }

This controls player a's turn, it will display the list of possible moves and then check if moves are available. The best place to display the number of moves would be to put a message before it lists the possible moves. See the Console.WriteLine below, you will also need to increment amoves. This is straight after the line to make the actual move:

  if (nextPlayer == "a")
                {
                    Console.WriteLine("Player A as made " + amoves + " moves");
                    ListPossibleMoves(board, A, nextPlayer, listOfMoves);
                    if (!ListEmpty(listOfMoves))
                    {
                        pieceIndex = SelectMove(listOfMoves);
                        MakeMove(board, A, B, listOfMoves, pieceIndex);
                        amoves++;
                        nextPlayer = SwapPlayer(nextPlayer);
                    }
                    else
                    {
                        gameEnd = true;
                    }
                }

Now we need to repeat this for player b's turn, this is controlled by the else section of the above if statement:

  else
                {
                    Console.WriteLine("Player B as made " + bmoves + " moves");
                    ListPossibleMoves(board, B, nextPlayer, listOfMoves);
                    if (!ListEmpty(listOfMoves))
                    {
                        pieceIndex = SelectMove(listOfMoves);
                        MakeMove(board, B, A, listOfMoves, pieceIndex);
                        bmoves++;
                        nextPlayer = SwapPlayer(nextPlayer);
                    }
                    else
                    {
                        gameEnd = true;
                    }
                }