A-level Computing/AQA/Paper 1/Skeleton program/2023

From Wikibooks, open books for an open world
Jump to navigation Jump to search

This is for the AQA A Level Computer Science Specification.

This is where suggestions can be made about what some of the questions might be and how we can solve them.

Please be respectful and do not vandalise the page, as this would affect students' preparation for exams!

Please do not discuss questions on this page. Instead use the discussion page.

The A Level exam involving this Skeleton Program has been completed. Good luck to everyone waiting for results!

Section C Predictions[edit | edit source]

The 2023 paper 1 will contain 6 questions worth 13 marks. As long as you know the program well, this will be a walk in the park:

Here are a mock set of questions (for Python 3):

7.1 State the name of an identifier for a public method in the Dastan class [1 mark]

7.2 Explain why this method is public and not private [2 marks]

8. How many points do you lose when you choose a move from position 1, 2 and 3 in the queue? [2 marks]

9.1 Suppose you wanted to display the grid with 8 by 8 cells. What would you modify in the program? [1 mark]

9.2. State the name of an identifier for a class that inherits from another class  [1 mark]

9.3 State the name of an identifier for a private method that has three parameters (including the object parameter). [1 mark]

10.1 State the name of an identifier that is a Boolean variable [1 mark]

10.2 What is the random module used for in the pre-release? [1 mark]

11.1 State the name of a built-in function [1 mark]

11.2 What effect does the super routine in class Kotla have? [1 mark]

12. Give an example from the code of an object instantiation? [1 mark]

13. give an example and reason for the use of polymorphism in the code? [3 marks]


Answers

7.1 State the name of an identifier for a public method in the Dastan class [1 mark] PlayGame

7.2 Explain why this method is public and not private [2 marks] It allows it to be accessed from outside the class by the main functions, otherwise if it was a private method this would not be possible.

8. How many points do you lose when you choose a move from position 1, 2 and 3 in the queue? [2 marks] 1,4,7

9.1 Suppose you wanted to display the grid with 8 by 8 cells. What would you modify in the program? [1 mark] Change this line: ThisGame = Dastan(6, 6, 4) to ThisGame = Dastan(8, 8, 4)

9.2 State the name of an identifier for a class that inherits from another class [1 mark] Kotla

9.3 State the name of an identifier for a private method that has three parameters (including the object parameter). [1 mark] e.g. __CreateMoveOption

10.1 State the name of an identifier that is a Boolean variable [1 mark] e.g. GameOver

10.2 What is the random module used for in the pre-release? [1 mark] Randomly selects the move offer option

11.1 State the name of a built-in function [1 mark] eg. print, int, float, input, str

11.2 What effect does the super routine in class Kotla have? [1 mark] Can use method class in the parent class, even if overridden

12. Give an example from the code of object instantiation? [1 mark] Thisgame= Dastan(6,6,4)

Section D Predictions[edit | edit source]

Programming Questions on Skeleton Program

  • The 2023 paper 1 contains 4 questions: a 5 mark, a 9 mark question, a 10 mark question and one 13 mark question - these marks include the screen capture(s), so the likely marks for the coding will be 1-2 marks lower.
  • The 2022 paper 1 contained 4 questions: a 5 mark, a 9 mark question, a 11 mark question and one 13 mark question - these marks include the screen capture(s), so the likely marks for the coding will be 1-2 marks lower.
  • The 2021 paper 1 contained 4 questions: a 6 mark, an 8 mark question, a 9 mark question and one 14 mark question - these marks include the screen capture(s), so the likely marks for the coding will be 1-2 marks lower.
  • The 2020 paper 1 contained 4 questions: a 6 mark, an 8 mark question, a 11 mark question and one 12 mark question - these marks include the screen capture(s), so the likely marks for the coding will be 1-2 marks lower.
  • The 2019 paper 1 contained 4 questions: a 5 mark, an 8 mark question, a 9 mark question and one 13 mark question - these marks include the screen capture(s), so the marks for the coding will be 1-2 marks lower.
  • The 2018 paper 1 contained 5 questions: a 2 mark question, a 5 mark question, two 9 mark questions, and one 12 mark question - these marks include the screen capture(s).
  • The 2017 paper 1 contained 5 questions: a 5 mark question, three 6 mark questions, and one 12 mark question.

Current questions are speculation by contributors to this page.

New Move: TibbleCross[edit | edit source]

Description of problem: The program is to be extended with a new type of move called the "TibbleCross". This move can allow a piece to go up two spaces diagonally from its starting position in any direction ( NW, NE, SE, SW ).

Add this move so it appears first in the queue of moves for both players.

Select the move and test it by selecting piece "22" and then moving to row/column "44"

C#:

private void CreateMoveOptionOffer()
        {
            MoveOptionOffer.Add("tibblecross");
            MoveOptionOffer.Add("jazair");
            MoveOptionOffer.Add("chowkidar");
            MoveOptionOffer.Add("cuirassier");
            MoveOptionOffer.Add("ryott");
            MoveOptionOffer.Add("faujdar");
        }

        private MoveOption CreateRyottMoveOption(int Direction)
        {
            MoveOption NewMoveOption = new MoveOption("ryott");
            Move NewMove = new Move(0, 1 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(0, -1 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(1 * Direction, 0);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(-1 * Direction, 0);
            NewMoveOption.AddToPossibleMoves(NewMove);
            return NewMoveOption;
        }

        private MoveOption CreateFaujdarMoveOption(int Direction)
        {
            MoveOption NewMoveOption = new MoveOption("faujdar");
            Move NewMove = new Move(0, -1 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(0, 1 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(0, 2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(0, -2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            return NewMoveOption;
        }

        private MoveOption CreateJazairMoveOption(int Direction)
        {
            MoveOption NewMoveOption = new MoveOption("jazair");
            Move NewMove = new Move(2 * Direction, 0);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(2 * Direction, -2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(2 * Direction, 2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(0, 2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(0, -2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(-1 * Direction, -1 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(-1 * Direction, 1 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            return NewMoveOption;
        }

        private MoveOption CreateCuirassierMoveOption(int Direction)
        {
            MoveOption NewMoveOption = new MoveOption("cuirassier");
            Move NewMove = new Move(1 * Direction, 0);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(2 * Direction, 0);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(1 * Direction, -2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(1 * Direction, 2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            return NewMoveOption;
        }

        private MoveOption CreateChowkidarMoveOption(int Direction)
        {
            MoveOption NewMoveOption = new MoveOption("chowkidar");
            Move NewMove = new Move(1 * Direction, 1 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(1 * Direction, -1 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(-1 * Direction, 1 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(-1 * Direction, -1 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(0, 2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(0, -2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            return NewMoveOption;
        }

        private MoveOption CreateTibbleCrossMoveOption(int Direction)
        {
            MoveOption NewMoveOption = new MoveOption("tibblecross");
            Move NewMove = new Move(2 * Direction, 2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(2 * Direction, -2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(-2 * Direction, 2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            NewMove = new Move(-2 * Direction, -2 * Direction);
            NewMoveOption.AddToPossibleMoves(NewMove);
            return NewMoveOption;
        }

        private MoveOption CreateMoveOption(string Name, int Direction)
        {
            if (Name == "tibblecross")
            {
                return CreateTibbleCrossMoveOption(Direction);
            }
            else if (Name == "chowkidar")
            {
                return CreateChowkidarMoveOption(Direction);
            }
            else if (Name == "ryott")
            {
                return CreateRyottMoveOption(Direction);
            }
            else if (Name == "faujdar")
            {
                return CreateFaujdarMoveOption(Direction);
            }
            else if (Name == "jazair")
            {
                return CreateJazairMoveOption(Direction);
            }
            else
            {
                return CreateCuirassierMoveOption(Direction);
            }
        }

        private void CreateMoveOptions()
        {
            Players[0].AddToMoveOptionQueue(CreateMoveOption("tibblecross", 1));
            Players[0].AddToMoveOptionQueue(CreateMoveOption("ryott", 1));
            Players[0].AddToMoveOptionQueue(CreateMoveOption("chowkidar", 1));
            Players[0].AddToMoveOptionQueue(CreateMoveOption("cuirassier", 1));
            Players[0].AddToMoveOptionQueue(CreateMoveOption("faujdar", 1));
            Players[0].AddToMoveOptionQueue(CreateMoveOption("jazair", 1));
            Players[1].AddToMoveOptionQueue(CreateMoveOption("tibblecross", -1));
            Players[1].AddToMoveOptionQueue(CreateMoveOption("ryott", -1));
            Players[1].AddToMoveOptionQueue(CreateMoveOption("chowkidar", -1));
            Players[1].AddToMoveOptionQueue(CreateMoveOption("jazair", -1));
            Players[1].AddToMoveOptionQueue(CreateMoveOption("faujdar", -1));
            Players[1].AddToMoveOptionQueue(CreateMoveOption("cuirassier", -1));
        }
    }


Delphi/Pascal:


Java:

private MoveOption createTibbleCrossMoveOption(int direction) {
        MoveOption newMoveOption = new MoveOption("tibblecross");
        Move newMove = new Move(2 * direction, 2 * direction);
        newMoveOption.addToPossibleMoves(newMove);
        newMove = new Move(-2 * direction, 2 * direction);
        newMoveOption.addToPossibleMoves(newMove);
        newMove = new Move(2 * direction, -2 * direction);
        newMoveOption.addToPossibleMoves(newMove);
        newMove = new Move(-2 * direction, -2 * direction);
        newMoveOption.addToPossibleMoves(newMove);     
        return newMoveOption;
    }

    private MoveOption createMoveOption(String name, int direction) {
        switch (name) {
            case "tibblecross":
                return createTibbleCrossMoveOption(direction);
            case "chowkidar":
                return createChowkidarMoveOption(direction);
            case "ryott":
                return createRyottMoveOption(direction);
            case "faujdar":
                return createFaujdarMoveOption(direction);
            case "jazair":
                return createJazairMoveOption(direction);
            default:
                return createCuirassierMoveOption(direction);
        }
    }

    private void createMoveOptions(){
        players.get(0).addToMoveOptionQueue(createMoveOption("tibblecross", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("ryott", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("chowkidar", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("cuirassier", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("faujdar", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("jazair", 1));        
        players.get(1).addToMoveOptionQueue(createMoveOption("tibblecross", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("ryott", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("chowkidar", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("jazair", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("faujdar", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("cuirassier", -1));
    }


Python:

def __CreateMoveOptionOffer(self):
    self._MoveOptionOffer.append("tibblecross") #append the new option
    self._MoveOptionOffer.append("jazair")
    self._MoveOptionOffer.append("chowkidar")
    self._MoveOptionOffer.append("cuirassier")
    self._MoveOptionOffer.append("ryott")
    self._MoveOptionOffer.append("faujdar")

def __CreateTibbleCrossMoveOption(self, Direction):
    NewMoveOption = MoveOption("tibblecross")
    NewMove = Move(2 * Direction,2 * Direction)
    NewMoveOption.AddToPossibleMoves(NewMove)
    NewMove = Move(-2 * Direction,2 * Direction)
    NewMoveOption.AddToPossibleMoves(NewMove)
    NewMove = Move(2 * Direction,-2 * Direction)
    NewMoveOption.AddToPossibleMoves(NewMove)
    NewMove = Move(-2 * Direction,-2 * Direction)
    NewMoveOption.AddToPossibleMoves(NewMove)
    return NewMoveOption

def __CreateMoveOption(self, Name, Direction):
    if Name == "tibblecross":
        return self.__CreateTibbleCrossMoveOption(Direction) ## add the move ##
    elif Name == "chowkidar":
        return self.__CreateChowkidarMoveOption(Direction)
    elif Name == "ryott":
        return self.__CreateRyottMoveOption(Direction)
    elif Name == "faujdar":
        return self.__CreateFaujdarMoveOption(Direction)
    elif Name == "jazair":
        return self.__CreateJazairMoveOption(Direction)
    else:
        return self.__CreateCuirassierMoveOption(Direction)

def __CreateMoveOptions(self):
    self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("tibblecross", 1)) ## add to player 1 ##
    self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("ryott", 1))
    self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("chowkidar", 1))
    self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("cuirassier", 1))
    self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("faujdar", 1))
    self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("jazair", 1))

    self._Players[1].AddToMoveOptionQueue(self.__CreateMoveOption("tibblecross", -1)) ## add to player 2 ##
    self._Players[1].AddToMoveOptionQueue(self.__CreateMoveOption("ryott", -1))
    self._Players[1].AddToMoveOptionQueue(self.__CreateMoveOption("chowkidar", -1))
    self._Players[1].AddToMoveOptionQueue(self.__CreateMoveOption("jazair", -1))
    self._Players[1].AddToMoveOptionQueue(self.__CreateMoveOption("faujdar", -1))
    self._Players[1].AddToMoveOptionQueue(self.__CreateMoveOption("cuirassier", -1))

#edit: please also remember to change the randint value in __UseMoveOptionOffer making it
#self.__MoveOptionOfferPosition = random.randint(0, 5)
  1. creds to ella and yani


VB.NET:

  Private Sub CreateMoveOptionOffer()
            MoveOptionOffer.Add("jazair")
            MoveOptionOffer.Add("chowkidar")
            MoveOptionOffer.Add("cuirassier")
            MoveOptionOffer.Add("ryott")
            MoveOptionOffer.Add("faujdar")
            MoveOptionOffer.Add("TibbleCross")
        End Sub
   Private Function CreateTibbleCrossMoveOption(ByVal Direction As Integer) As MoveOption
            Dim NewMoveOption As MoveOption = New MoveOption("TibbleCross")
            Dim NewMove As Move = New Move(2 * Direction, 2 * Direction)
            NewMoveOption.AddToPossibleMoves(NewMove)
            NewMove = New Move(-2 * Direction, 2 * Direction)
            NewMoveOption.AddToPossibleMoves(NewMove)
            NewMove = New Move(2 * Direction, -2 * Direction)
            NewMoveOption.AddToPossibleMoves(NewMove)
            NewMove = New Move(-2 * Direction, -2 * Direction)
            NewMoveOption.AddToPossibleMoves(NewMove)
            Return NewMoveOption
        End Function

        Private Function CreateMoveOption(ByVal Name As String, ByVal Direction As Integer) As MoveOption
            If Name = "chowkidar" Then
                Return CreateChowkidarMoveOption(Direction)
            ElseIf Name = "ryott" Then
                Return CreateRyottMoveOption(Direction)
            ElseIf Name = "faujdar" Then
                Return CreateFaujdarMoveOption(Direction)
            ElseIf Name = "jazair" Then
                Return CreateJazairMoveOption(Direction)
            ElseIf Name = "cuirassier" Then
                Return CreateCuirassierMoveOption(Direction)
            Else
                Return CreateTibbleCrossMoveOption(Direction)
            End If
        End Function

        Private Sub CreateMoveOptions()
            Players(0).AddToMoveOptionQueue(CreateMoveOption("TibbleCross", 1))
            Players(0).AddToMoveOptionQueue(CreateMoveOption("ryott", 1))
            Players(0).AddToMoveOptionQueue(CreateMoveOption("chowkidar", 1))
            Players(0).AddToMoveOptionQueue(CreateMoveOption("cuirassier", 1))
            Players(0).AddToMoveOptionQueue(CreateMoveOption("faujdar", 1))
            Players(0).AddToMoveOptionQueue(CreateMoveOption("jazair", 1))
            Players(1).AddToMoveOptionQueue(CreateMoveOption("TibbleCross", -1))
            Players(1).AddToMoveOptionQueue(CreateMoveOption("ryott", -1))
            Players(1).AddToMoveOptionQueue(CreateMoveOption("chowkidar", -1))
            Players(1).AddToMoveOptionQueue(CreateMoveOption("jazair", -1))
            Players(1).AddToMoveOptionQueue(CreateMoveOption("faujdar", -1))
            Players(1).AddToMoveOptionQueue(CreateMoveOption("cuirassier", -1))
        End Sub


New Move: rook[edit | edit source]

Description of problem: Add a new move which moves forward until the piece hits the end of the board or hits another piece

C#:

// Line 35 should be moved to Line 38, underneath `CreatePieces(NoOfPieces)`
// The line content is `CreateMoveOptions()`

// Line 304
  private void CreateMoveOptionOffer() {
    MoveOptionOffer.Add("jazair");
    MoveOptionOffer.Add("chowkidar");
    MoveOptionOffer.Add("cuirassier");
    MoveOptionOffer.Add("ryott");
    MoveOptionOffer.Add("faujdar");
    MoveOptionOffer.Add("rook");
//  ^^ THIS LINE WAS ADDED ^^
  }

// Line 387

// START OF ADDED SECTION
  private MoveOption CreateRookMoveOption(int Direction) {
    MoveOption NewMoveOption = new MoveOption("rook");
    for (int row = 1; row < NoOfRows; ++row) 
    {
      int Index = Direction < 0 ? (row - 1) * 10 : (NoOfRows - row - 2) * 10;
      if (Board[Index].GetPieceInSquare() != null) 
         {
             break;
         }
      Move NewMove = new Move(row * Direction, 0);
      NewMoveOption.AddToPossibleMoves(NewMove);
    }
    return NewMoveOption;
  }
// END OF ADDED SECTION


// Line 410, within the `CreateMoveOption function`
...
else if (Name == "rook") {
      return CreateRookMoveOption(Direction);
}
...

// Modified `CreateMoveOptions` at Line 417
  private void CreateMoveOptions() {
    Players[0].AddToMoveOptionQueue(CreateMoveOption("rook", 1));
//  ^^^^^^^^^^^^^^^^^^ THIS LINE WAS ADDED ^^^^^^^^^^^^^^^^^^^^
    Players[0].AddToMoveOptionQueue(CreateMoveOption("ryott", 1));
    Players[0].AddToMoveOptionQueue(CreateMoveOption("chowkidar", 1));
    Players[0].AddToMoveOptionQueue(CreateMoveOption("cuirassier", 1));
    Players[0].AddToMoveOptionQueue(CreateMoveOption("faujdar", 1));
    Players[0].AddToMoveOptionQueue(CreateMoveOption("jazair", 1));
    Players[1].AddToMoveOptionQueue(CreateMoveOption("rook", -1));
//  ^^^^^^^^^^^^^^^^^^ THIS LINE WAS ADDED ^^^^^^^^^^^^^^^^^^^^
    Players[1].AddToMoveOptionQueue(CreateMoveOption("ryott", -1));
    Players[1].AddToMoveOptionQueue(CreateMoveOption("chowkidar", -1));
    Players[1].AddToMoveOptionQueue(CreateMoveOption("jazair", -1));
    Players[1].AddToMoveOptionQueue(CreateMoveOption("faujdar", -1));
    Players[1].AddToMoveOptionQueue(CreateMoveOption("cuirassier", -1));
  }

// This is not required, I just found it made the Illegal Moves a tad more
// obvious

// Line 264
if (MoveLegal) {
...
}
// START OF ADDED SECTION
else {
    Console.WriteLine("\x1b[31;1mIllegal Move ({0}, {1})\x1b[0;0m", StartSquareReference, FinishSquareReference);
}
// END OF ADDED SECTION


Delphi/Pascal:


Java:

   public Dastan(int r, int c, int noOfPieces ){
        
        // change order of initialisation to enable createMoveOptions to work for rook
        // board needs to be created first to check max movement going forward.
        
        players.add(new Player("Player One", 1));
        players.add(new Player("Player Two", -1));
        noOfRows = r;
        noOfColumns = c;
        createBoard();
        createMoveOptions();
        moveOptionOfferPosition = 0;
        createMoveOptionOffer();
        createPieces(noOfPieces);
        currentPlayer = players.get(0);
    }
// changes made to createMoveOption
private MoveOption createMoveOption(String name, int direction) {
        switch (name) {

            case "chowkidar":
                return createChowkidarMoveOption(direction);
            case "ryott":
                return createRyottMoveOption(direction);
            case "faujdar":
                return createFaujdarMoveOption(direction);
            case "jazair":
                return createJazairMoveOption(direction);
            // added rook    
            case "rook":
                return createRookMoveOption(direction);
            default:
                return createCuirassierMoveOption(direction);
        }
    }
// add new MoveOption method
 private MoveOption createRookMoveOption (int Direction) {
        MoveOption NewMoveOption = new MoveOption("rook");

        for (int row = 1; row < this.noOfRows; row++) {
            int Index = Direction < 0 ? (row - 1) * 10 : (noOfRows - row - 2) * 10;
            if (board.get(index).getPieceInSquare() != null) {
                break;
            }
            Move NewMove = new Move(row * Direction, 0);
            NewMoveOption.addToPossibleMoves(NewMove);
        }
        return NewMoveOption;
    }

 private void createMoveOptions(){
        // added new move rook
        players.get(0).addToMoveOptionQueue(createMoveOption("rook", 1));
        //
        players.get(0).addToMoveOptionQueue(createMoveOption("ryott", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("chowkidar", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("cuirassier", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("faujdar", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("jazair", 1));
        // added new move rook
        players.get(1).addToMoveOptionQueue(createMoveOption("rook", -1));
        //
        players.get(1).addToMoveOptionQueue(createMoveOption("ryott", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("chowkidar", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("jazair", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("faujdar", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("cuirassier", -1));
    }
}


Python:

while not SquareIsValid:
                StartSquareReference = self.__GetSquareReference("containing the piece to move")
                SquareIsValid = self.__CheckSquareIsValid(StartSquareReference, True)
            SquareIsValid = False
          
            #this is what changed   
            while not SquareIsValid:
               
                if self._CurrentPlayer.GetQueue(Choice) == "castle":
                    SquareIsValid = True
                    
                    FinishSquareReference = StartSquareReference
                    while SquareIsValid:
                        
                        FinishSquareReference =int(str((int(str(FinishSquareReference)[0])+(1)*self._CurrentPlayer.GetDirection()))+str(FinishSquareReference)[1])
                        
                        
                        SquareIsValid = self.__CheckSquareIsValid(FinishSquareReference, False)
                        if SquareIsValid == False:
                            FinishSquareReference =int(str((int(str(FinishSquareReference)[0])-(1)*self._CurrentPlayer.GetDirection()))+str(FinishSquareReference)[1])
                            
                        elif ( self.__CalculatePieceCapturePoints(FinishSquareReference))!=0:
                           
                            FinishSquareReference =int(str((int(str(FinishSquareReference)[0])-(1)*self._CurrentPlayer.GetDirection()))+str(FinishSquareReference)[1])
                            SquareIsValid = True
                            break
                else:
                    FinishSquareReference = self.__GetSquareReference("to move to")
                if SquareIsValid == False:
                    SquareIsValid = self.__CheckSquareIsValid(FinishSquareReference, False)
            #this is the end of what is changed    
                
    
                    
            MoveLegal = self._CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, FinishSquareReference)
           
            if MoveLegal:
                PointsForPieceCapture = self.__CalculatePieceCapturePoints(FinishSquareReference)
                self._CurrentPlayer.ChangeScore(-(Choice + (2 * (Choice - 1))))
                self._CurrentPlayer.UpdateQueueAfterMove(Choice)
                self.__UpdateBoard(StartSquareReference, FinishSquareReference)
                self.__UpdatePlayerScore(PointsForPieceCapture)
            print("New score: " + str(self._CurrentPlayer.GetScore()) + "\n")
            if self._CurrentPlayer.SameAs(self._Players[0]):
                self._CurrentPlayer = self._Players[1]
            else:
                self._CurrentPlayer = self._Players[0]
            GameOver = self.__CheckIfGameOver()
        self.__DisplayState()
        self.__DisplayFinalResult()
def GetQueue(self,Pos):
        Temp = self.__Queue.GetMoveOptionInPosition(Pos - 1).GetName()
        return Temp


VB.NET:


Checking validity of a move[edit | edit source]

Description of problem: When choosing where to move a piece, you must input the start square and finish square. If a valid start square is chosen, but an invalid destination square, the program will move on without prompting the player to re-enter.  

Alter the code to prompt the user to re-enter the finish square until a valid square is given.

C#:

// The changes for this are at the while loop at line 258 in the PlayGame method of the Dastan class

// Move the definition of MoveLegal in front of the while loop
bool MoveLegal = false;
// Make the while loop conditional on both the MoveLegal and SquareIsValid, could also be (!SquareIsValid || !MoveLegal)
while (!(SquareIsValid && MoveLegal))
{
    FinishSquareReference = GetSquareReference("to move to");
    SquareIsValid = CheckSquareIsValid(FinishSquareReference, false);
    // Check if the move is legal in the loop
    MoveLegal = CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, FinishSquareReference);
    
    // Give some output if it is an illegal move
    if (!MoveLegal)
        Console.WriteLine("Cannot move to that square with this move");
 
    if (!SquareIsValid)
        Console.WriteLine("Invalid position");
}
//bool MoveLegal = CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, FinishSquareReference);


Delphi/Pascal:


Java:

public void playGame() {
        boolean gameOver = false;
        while (!gameOver) {
            displayState();
            boolean squareIsValid = false;
            int choice;
            do {
                Console.write("Choose move option to use from queue (1 to 3) or 9 to take the offer: ");
                choice = Integer.parseInt(Console.readLine());
                if (choice == 9) {
                    useMoveOptionOffer();
                    displayState();
                }
            } while (choice < 1 || choice > 3);
            int startSquareReference = 0;
            while (!squareIsValid) {
                startSquareReference = getSquareReference("containing the piece to move");
                squareIsValid = checkSquareIsValid(startSquareReference, true);
            }
            int finishSquareReference = 0;

            boolean moveLegal = false; //set up move legal here

            while (!moveLegal) { //change the loop to look at moveLegal
                finishSquareReference = getSquareReference("to move to");
                squareIsValid = checkSquareIsValid(finishSquareReference, false);
                if (squareIsValid){
                    //Calculate moveLegal
                    moveLegal = currentPlayer.checkPlayerMove(choice, startSquareReference, finishSquareReference);
                }
            }
            
            //Can remove the chack to moveLegal here as it will be
            int pointsForPieceCapture = calculatePieceCapturePoints(finishSquareReference);
            currentPlayer.changeScore(-(choice + (2 * (choice - 1))));
 //etc.


Python:

class Dastan:
    ...
    def PlayGame(self):
        ...
        MoveLegal = False  # change from SqureIsValid = False
        while not MoveLegal:  # change from while not SquareIsValid:
            FinishSquareReference = self.__GetSquareReference("to move to")
            SquareIsValid = self.__CheckSquareIsValid(FinishSquareReference, False)
	        if SquareIsValid: # Need to check that the square is both valid and legal first, otherwise can take own pieces
	            MoveLegal = self._CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference,FinishSquareReference)  # bring MoveLegal check into while loop so that it asks until the Finish Square move is legal

        # remove if MoveLegal: as it is now guaranteed to be True
        PointsForPieceCapture = self.__CalculatePieceCapturePoints(FinishSquareReference)
        self._CurrentPlayer.ChangeScore(-(Choice + (2 * (Choice - 1))))
        self._CurrentPlayer.UpdateQueueAfterMove(Choice)
        self.__UpdateBoard(StartSquareReference, FinishSquareReference)
        self.__UpdatePlayerScore(PointsForPieceCapture)
        print("New score: " + str(self._CurrentPlayer.GetScore()) + "\n")

        ...


VB.NET:

  While Not SquareIsValid Or MoveLegal = False
                    FinishSquareReference = GetSquareReference("to move to")
                    SquareIsValid = CheckSquareIsValid(FinishSquareReference, False)
                    MoveLegal = CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, FinishSquareReference)
  End While


New Move: spacejump[edit | edit source]

Description of problem: Add a new move called a spacejump which moves the chosen piece to a random place on the board. It can't land on your own pieces, but everywhere else is fine. The player cannot choose where the piece will end up. The spacejump move will not be added to the queue of moves, instead a player is allowed one per game that can be used whenever they choose in lieu of a queue choice. Test by allowing player 1 to use the option from square 22 and then player 2 from square 55. Player 1 will not have the option displayed on their next turn.

C#:

public void PlayGame()
        { 
            /* Only one time use is not implemented*/
            /* SUMMARY  - option of pressing 8 for a spacejump is implemented and the 'finishsquarereferance' is randomly generated instead of asking for user input*/
            bool GameOver = false;
            while (!GameOver)
            {
                DisplayState();
                bool SquareIsValid = false;
                int Choice;
                do
                {
                    Console.Write("Choose move option to use from queue (1 to 3) or 8 to make a space jump or 9 to take the offer: "); //added the option of pressubg 8 for a space jump
                    Choice = Convert.ToInt32(Console.ReadLine());
                    if (Choice == 9)
                    {
                        UseMoveOptionOffer();
                        DisplayState();
                    }
                }
                while (!(Choice != 1 || Choice != 2 || Choice != 3 || Choice != 8)); //adding 8 to the clause so that the loop can be escaped
                int StartSquareReference = 0;
                while (!SquareIsValid)
                {
                    StartSquareReference = GetSquareReference("containing the piece to move");
                    SquareIsValid = CheckSquareIsValid(StartSquareReference, true);
                }
                int FinishSquareReference = 0;
                if (Choice != 8) //if they choose 1, 2 or 3 then this asks the user to input their finish square referenace as normal
                {
                    SquareIsValid = false;
                    bool MoveLegal = false; //moved the definition of movelegal so the issue of user picking a valid square that is not within the bounds of a move skips their turn
                    while (!SquareIsValid || !MoveLegal)                                        
                    {
                        FinishSquareReference = GetSquareReference("to move to");
                        SquareIsValid = CheckSquareIsValid(FinishSquareReference, false);
                        MoveLegal = CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, FinishSquareReference);
                    }
                    //from here it updates the baord and calaculates points as normal
                    int PointsForPieceCapture = CalculatePieceCapturePoints(FinishSquareReference);
                    CurrentPlayer.ChangeScore(-(Choice + (2 * (Choice - 1))));
                    CurrentPlayer.UpdateQueueAfterMove(Choice);
                    UpdateBoard(StartSquareReference, FinishSquareReference);
                    UpdatePlayerScore(PointsForPieceCapture);
                    Console.WriteLine("New score: " + CurrentPlayer.GetScore() + Environment.NewLine);
                }
                else //if their choice is 8 then it randomly generates a finish square referance
                {
                    do
                    {       // do-while loop so that if the 'finishsquarereferance' does not equal the 'startsquarereferance'
                        FinishSquareReference = RGen.Next(1, NoOfRows) * 10 + RGen.Next(1, NoOfColumns); //1 to NoOfColumns & 1 to NoOfRows
SquareIsValid = CheckSquareIsValid(FinishSquareReference, false);
                    } while (FinishSquareReference == StartSquareReference && !SquareIsValid);                            //because lists are 0 based
                    //calcualtes points and updates the board
                    //removed line 'CurrentPlayer.UpdateQueueAfterMove(Choice);
                    int PointsForPieceCapture = CalculatePieceCapturePoints(FinishSquareReference);
                    CurrentPlayer.ChangeScore(-(Choice + (2 * (Choice - 1))));
                    UpdateBoard(StartSquareReference, FinishSquareReference);
                    UpdatePlayerScore(PointsForPieceCapture);
                    Console.WriteLine("New score: " + CurrentPlayer.GetScore() + Environment.NewLine);
                }
                if (CurrentPlayer.SameAs(Players[0]))
                {
                    CurrentPlayer = Players[1];
                }
                else
                {
                    CurrentPlayer = Players[0];
                }
                GameOver = CheckIfGameOver();
            }
            DisplayState();
            DisplayFinalResult();
        }


Delphi/Pascal:


Java:

class Player {
    private String name; 
    private int direction, score; 
    private MoveOptionQueue queue = new MoveOptionQueue();
    private boolean spaceJumpUsed;
    

    public Player(String n, int d) {
        score = 100;
        name = n;
        direction = d;
        spaceJumpUsed=false;
    }

    public boolean getspaceJumpUsed(){
        return spaceJumpUsed; 
    }
    
    public void setspaceJumpUsed(boolean newValue){
        spaceJumpUsed=newValue;
    }
    //etc.

public void playGame() {
        boolean gameOver = false;
        while (!gameOver) {
            displayState();
            boolean squareIsValid = false;
            char spaceJumpChoice = 'n';
            if (!currentPlayer.getSpaceJumpUsed()) {
                Console.println(" Do you want to space jump (y/n). "
                        + "You can only do this once in a game: ");
                spaceJumpChoice = Console.readLine().charAt(0);
            }

            if (spaceJumpChoice == 'n') {
                //Continue with normal execution
                int choice;
                do {
                    Console.write("Choose move option to use from queue (1 to 3) or 9 to take the offer: ");
                    choice = Integer.parseInt(Console.readLine());
                    if (choice == 9) {
                        useMoveOptionOffer();
                        displayState();
                    }
                } while (choice < 1 || choice > 3);
                int startSquareReference = 0;
                while (!squareIsValid) {
                    startSquareReference = getSquareReference("containing the piece to move");
                    squareIsValid = checkSquareIsValid(startSquareReference, true);
                }
                int finishSquareReference = 0;
                squareIsValid = false;
                while (!squareIsValid) {
                    finishSquareReference = getSquareReference("to move to");
                    squareIsValid = checkSquareIsValid(finishSquareReference, false);
                }
                boolean moveLegal = currentPlayer.checkPlayerMove(choice, startSquareReference, finishSquareReference);
                if (moveLegal) {
                    int pointsForPieceCapture = calculatePieceCapturePoints(finishSquareReference);
                    currentPlayer.changeScore(-(choice + (2 * (choice - 1))));
                    currentPlayer.updateQueueAfterMove(choice);
                    updateboard(startSquareReference, finishSquareReference);
                    updatePlayerScore(pointsForPieceCapture);
                    Console.writeLine("New score: " + currentPlayer.getScore() + System.lineSeparator());
                }
            } else {
                //do a spaceJump - use whatever can be used from normal execution above
                currentPlayer.setSpaceJumpUsed(true);
                int startSquareReference = 0;
                while (!squareIsValid) {
                    startSquareReference = getSquareReference("containing the piece to move");
                    squareIsValid = checkSquareIsValid(startSquareReference, true);
                }
                int finishSquareReference = 0;
                squareIsValid = false;
                while (!squareIsValid) {
                    //Generate a finish square reference within the range 0-99 and then validate it
                    finishSquareReference=rGen.nextInt(100);
                    squareIsValid = checkSquareIsValid(finishSquareReference, false);
                }
                    
                int pointsForPieceCapture = calculatePieceCapturePoints(finishSquareReference);                
                updateboard(startSquareReference, finishSquareReference);
                updatePlayerScore(pointsForPieceCapture);
                Console.writeLine("New score: " + currentPlayer.getScore() + System.lineSeparator());          
            }
            
            if (currentPlayer.sameAs(players.get(0))) {
                currentPlayer = players.get(1);
            } else {
                currentPlayer = players.get(0);
            }
            gameOver = checkIfGameOver();
        }
        displayState();
        displayFinalResult();
    }


Python:

______________________________________________________________________________________________________________________________

    # In Dastan class 
    def PlayGame(self):
        GameOver = False
        SpaceJump = False
        while not GameOver:
            self.__DisplayState()
            SquareIsValid = False
            Choice = 0
            while (Choice < 1 or Choice > 3) and Choice != 8:
                if self._CurrentPlayer.CanUseSpaceJump():
                    Choice = int(input("Choose move option to use from queue (1 to 3), 8 to use SpaceJump or 9 to take the offer: "))
                else:
                    Choice = int(input("Choose move option to use from queue (1 to 3), or 9 to take the offer: "))
                if Choice == 8:
                    if self._CurrentPlayer.CanUseSpaceJump():
                        SpaceJump = True
                    else:
                        Choice = 0  # Reset Choice to 0 so it asks again
                        print("You have already used SpaceJump this game")
                elif Choice == 9:
                    self.__UseMoveOptionOffer()
                    self.__DisplayState()
            while not SquareIsValid:
                StartSquareReference = self.__GetSquareReference("containing the piece to move")
                SquareIsValid = self.__CheckSquareIsValid(StartSquareReference, True)
            SquareIsValid = False
            while not SquareIsValid:
                if SpaceJump:
                    FinishSquareReference = random.randint(1, self._NoOfRows) * 10 + random.randint(1, self._NoOfColumns)
                else:
                    FinishSquareReference = self.__GetSquareReference("to move to")
                # CheckSquareIsValid already prevents you from moving to your own piece so no additional check is needed 
                SquareIsValid = self.__CheckSquareIsValid(FinishSquareReference, False)
            if SpaceJump:
                MoveLegal = True
            else:
                MoveLegal = self._CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, FinishSquareReference)
            if MoveLegal:
                PointsForPieceCapture = self.__CalculatePieceCapturePoints(FinishSquareReference)
                if SpaceJump:
                    # The question didn't specify a point cost for SpaceJump but I thought 22 was a bit much
                    # We also need a conditional here anyway as UpdateQueueAfterMove doesn't work when Choice=8
                    self._CurrentPlayer.ChangeScore(-10)
                    SpaceJump = False
                    self._CurrentPlayer.SetUsedSpaceJump(True)
                else:
                    self._CurrentPlayer.ChangeScore(-(Choice + (2 * (Choice - 1))))
                    self._CurrentPlayer.UpdateQueueAfterMove(Choice)
                self.__UpdateBoard(StartSquareReference, FinishSquareReference)
                self.__UpdatePlayerScore(PointsForPieceCapture)
                print("New score: " + str(self._CurrentPlayer.GetScore()) + "\n")
            if self._CurrentPlayer.SameAs(self._Players[0]):
                self._CurrentPlayer = self._Players[1]
            else:
                self._CurrentPlayer = self._Players[0]
            GameOver = self.__CheckIfGameOver()
        self.__DisplayState()
        self.__DisplayFinalResult()
______________________________________________________________________________________________________________________________

class Player:
    def __init__(self, N, D):
        self.__Score = 100
        self.__Name = N
        self.__Direction = D
        self.__Queue = MoveOptionQueue()
        self.__UsedSpaceJump = False  # Added private variable

    def CanUseSpaceJump(self):
        return not self.__UsedSpaceJump

    def SetUsedSpaceJump(self, Value):
        self.__UsedSpaceJump = Value

    # Other methods originally in Player are not edited
______________________________________________________________________________________________________________________________


VB.NET:

  #changes to PlayGame subroutine:
 Loop Until (Choice >= 1 And Choice <= 3) Or (CurrentPlayer.GetSpaceJump = False And Choice = 10)
                Dim StartSquareReference As Integer
                While Not SquareIsValid
                    StartSquareReference = GetSquareReference("containing the piece to move")
                    SquareIsValid = CheckSquareIsValid(StartSquareReference, True)
                End While
                Dim FinishSquareReference As Integer
                If Choice = 10 Then
                    FinishSquareReference = DoSpaceJump()
                Else
                    SquareIsValid = False
                    Console.WriteLine("Movelegal false")
                    Dim MoveLegal As Boolean = False
                    While Not SquareIsValid Or MoveLegal = False
                        FinishSquareReference = GetSquareReference("to move to")
                        SquareIsValid = CheckSquareIsValid(FinishSquareReference, False)
                        MoveLegal = CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, FinishSquareReference)
                    End While
                End If

#changes to Player class:

Private SpaceJump As Boolean = False
        Public Function GetSpaceJump()
            Return SpaceJump
        End Function
        Sub UseSpaceJump()
            SpaceJump = True
        End Sub

#Changes to Display Player State:

If CurrentPlayer.GetSpaceJump = False Then
                Console.WriteLine("Spacejump available! Write 10 for spacejump")
 End If

#New SpaceJump function(returns finish square reference):
Private Function DoSpaceJump() As Integer
            Dim random As New Random
            Dim ValidReference As Boolean = False
            Dim Reference As Integer
            While ValidReference = False
                Reference = random.Next(11, 66)
                If Board(GetIndexOfSquare(Reference)).GetPieceInSquare() IsNot Nothing Then
                    If   Board(GetIndexOfSquare(Reference)).GetPieceInSquare().GetBelongsTo() IsNot CurrentPlayer Then
                        ValidReference = True
                    End If
                End If
            End While
            CurrentPlayer.UseSpaceJump()
            Return Reference
 End Function


UserName input[edit | edit source]

At the beginning of the game allow each user to enter their own name to be used as a replacement to "Player One" and "Player Two"

C#:

 static void Main(string[] args)
        {
            //bercan

            Console.WriteLine("\t --- Welcome to DASTAN! --- \t");
            Console.WriteLine("\n");

            Console.WriteLine("Player a name for player one"); // get name for player 1
            string player1_name = Console.ReadLine();

            Console.WriteLine("Player a name for player two"); // get name for player 2
            string player2_name = Console.ReadLine();

            Console.WriteLine("\n");

            Dastan ThisGame = new Dastan(6, 6, 4, player1_name, player2_name); //enter the parameters
            ThisGame.PlayGame();
            Console.WriteLine("Goodbye!");
            Console.ReadLine();
        }
    }

    class Dastan
    {
        protected List<Square> Board;
        protected int NoOfRows, NoOfColumns, MoveOptionOfferPosition;
        protected List<Player> Players = new List<Player>();
        protected List<string> MoveOptionOffer = new List<string>();
        protected Player CurrentPlayer;
        protected Random RGen = new Random();

        public Dastan(int R, int C, int NoOfPieces , string player1_name , string player2_name) // parameters for the constructor
        {
            Players.Add(new Player(player1_name, 1)); // instead of "Player One" the parameter player1_name
            Players.Add(new Player(player2_name, -1)); // instead of "Player the" the parameter player2_name
            CreateMoveOptions();
            NoOfRows = R;
            NoOfColumns = C;
            MoveOptionOfferPosition = 0;
            CreateMoveOptionOffer();
            CreateBoard();
            CreatePieces(NoOfPieces);
            CurrentPlayer = Players[0];
        }


Delphi/Pascal:


Java:

//Class Dastan
    public Dastan(int r, int c, int noOfPieces ){
      
    	Console.writeLine("Player 1, enter your name: ");
    	String player1Name = Console.readLine();
        players.add(new Player(player1Name, 1));
        
        Console.writeLine("Player 2, enter your name: ");
    	String player2Name = Console.readLine();
        players.add(new Player(player2Name, -1));
        
        createMoveOptions();
        
        noOfRows = r;
        noOfColumns = c;
        moveOptionOfferPosition = 0;
        createMoveOptionOffer();
        createBoard();
        createPieces(noOfPieces);
        currentPlayer = players.get(0);
    }


Python:

class Dastan:
    def __init__(self, R, C, NoOfPieces):
        self._Board = []
        self._Players = []
        self._MoveOptionOffer = []
        playerOneName = input("Please enter player 1's name: ")
        self._Players.append(Player(playerOneName, 1))
        playerTwoName = input("Please enter player 2's name: ")
        self._Players.append(Player(playerTwoName, -1))
        self.__CreateMoveOptions()
...


VB.NET:


Show where the piece can move[edit | edit source]

Description of problem: At the moment when selecting a move the player is expected to remember the ways in which move can be applied. Modify the program so that, once a piece has been selected a '^' symbol appears in the squares into which that piece can be moved based on the move selected. - Resolve using method A1 specification

C#:

//Dastan class
private void DisplayBoardMoveOptions(Player CurrentPlayer, int Choice, int StartSquareReference)
{
    //A slightly altered DisplayBoard() but checks if each square is a possible square to move to using CurrentPlayer.CheckPlayerMove() and places "^" if it is

    //Adds Column axis labeling
    Console.Write(Environment.NewLine + "   ");
    for (int Column = 1; Column <= NoOfColumns; Column++)
    {
        Console.Write(Column.ToString() + "  ");
    }
    Console.Write(Environment.NewLine + "  ");
    for (int Count = 1; Count <= NoOfColumns; Count++)
    {
        Console.Write("---");
    }
    Console.WriteLine("-");

         
    for (int Row = 1; Row <= NoOfRows; Row++)
    {
        //For each row add the row labelling at the start (number and spacing)
        Console.Write(Row.ToString() + " ");
        for (int Column = 1; Column <= NoOfColumns; Column++)
        {
            //Either places a "^" for a possible place to move to ,a " " for an empty sqaure or the symbol for the piece in the square

            int Index = GetIndexOfSquare(Row * 10 + Column);
            Console.Write("|" + Board[Index].GetSymbol());
            Piece PieceInSquare = Board[Index].GetPieceInSquare();
            if (CheckSquareIsValid(Row * 10 + Column, false) && CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, Row * 10 + Column))
            {
                Console.Write("^");
            }
            else if (PieceInSquare == null)
            {
                Console.Write(" ");
            } 
            else
            {
                Console.Write(PieceInSquare.GetSymbol());
            }
        }
        Console.WriteLine("|");
    }
    Console.Write("  -");

    // Add spacing for the bottom of the board display
    for (int Column = 1; Column <= NoOfColumns; Column++)
    {
        Console.Write("---");
    }
    Console.WriteLine();
    Console.WriteLine();
}

public void PlayGame()
{
    bool GameOver = false;
    while (!GameOver)
    {
        DisplayState();
        bool SquareIsValid = false;
        int Choice;
        do
        {
            Console.Write("Choose move option to use from queue (1 to 3) or 9 to take the offer: ");
            Choice = Convert.ToInt32(Console.ReadLine());
            if (Choice == 9)
            {
                UseMoveOptionOffer();
                DisplayState();
            }
        }
        while (Choice < 1 || Choice > 3);
        int StartSquareReference = 0;
        while (!SquareIsValid)
        {
            StartSquareReference = GetSquareReference("containing the piece to move");
            SquareIsValid = CheckSquareIsValid(StartSquareReference, true);
        }
        int FinishSquareReference = 0;
        SquareIsValid = false;
        //Display possible move options using currentPlayer, the player choice number and the start point of the move
        DisplayBoardMoveOptions(CurrentPlayer,Choice,StartSquareReference);
        while (!SquareIsValid)
        {
            FinishSquareReference = GetSquareReference("to move to");
            SquareIsValid = CheckSquareIsValid(FinishSquareReference, false);
        }
        bool MoveLegal = CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, FinishSquareReference);
        if (MoveLegal)
        {
            int PointsForPieceCapture = CalculatePieceCapturePoints(FinishSquareReference);
            CurrentPlayer.ChangeScore(-(Choice + (2 * (Choice - 1))));
            CurrentPlayer.UpdateQueueAfterMove(Choice);
            UpdateBoard(StartSquareReference, FinishSquareReference);
            UpdatePlayerScore(PointsForPieceCapture);
            Console.WriteLine("New score: " + CurrentPlayer.GetScore() + Environment.NewLine);
        }
        if (CurrentPlayer.SameAs(Players[0]))
        {
            CurrentPlayer = Players[1];
        }
        else
        {
            CurrentPlayer = Players[0];
        }
        GameOver = CheckIfGameOver();
    }
    DisplayState();
    DisplayFinalResult();
}


Delphi/Pascal:


Java:

//Class Dastan
    // Now takes two parameters
    // The index of the players choice in the Move Option Queue
    // And the start square that the player has selected
    private void displayBoard(int choice, int startSquareReference){
        Console.write(System.lineSeparator() + "   ");
        for (int column = 1; column <= noOfColumns; column++) {
            Console.write(column + "  ");
        }
        Console.write(System.lineSeparator() + "  ");
        for (int count = 1; count <= noOfColumns; count++) {
            Console.write("---");
        }
        Console.writeLine("-");
        for (int row = 1; row <= noOfRows; row++) {
            Console.write(row + " ");
            for (int column = 1; column <= noOfColumns; column++) {
                int index = getIndexOfSquare(row * 10 + column);
                Console.write("|" + board.get(index).getSymbol());
                Piece pieceInSquare = board.get(index).getPieceInSquare();
                if (pieceInSquare == null) {
                	// START OF ADDED SECTION
                	// Doesn't display the possible moves if -1 is passed as the choice
                	if (choice != -1) {
                		
                		//This is the row and column in the format that checkPlayerMove takes
                		int endSquareReference = Integer.parseInt(row+""+column);
            
                		// Displays a ^ if checkPlayerMove returns true with the arguments below
	                	if (currentPlayer.checkPlayerMove(choice, startSquareReference, endSquareReference)) {
	                        Console.write("^");
	                	}
	                	else {
	                        Console.write(" ");
	                	}
                	}
                	else {
                        Console.write(" ");
                	}
                	// END OF ADDED SECTION
                } else {
                    Console.write(pieceInSquare.getSymbol());
                }
            }
            Console.writeLine("|");
        }
        Console.write("  -");
        for (int column = 1; column <= noOfColumns; column++) {
            Console.write("---");
        }
        Console.writeLine();
        Console.writeLine();
    }



//Class Dastan
    private void displayState(){
        // Displays the board in the normal format is -1 is passed as the choice
        //START OF ADDED SECTION
        displayBoard(-1, -1);
        //END OF ADDED SECTION
        Console.writeLine("Move option offer: " + moveOptionOffer.get(moveOptionOfferPosition));
        Console.writeLine();
        Console.writeLine(currentPlayer.getPlayerStateAsString());
        Console.writeLine("Turn: " + currentPlayer.getName());
        Console.writeLine();
    }





//Class Dastan
    public void playGame() {
        boolean gameOver = false;
        while (!gameOver) {
            displayState();
            boolean squareIsValid = false;
            int choice;
            do {
                Console.write("Choose move option to use from queue (1 to 3) or 9 to take the offer: ");
                choice = Integer.parseInt(Console.readLine());
                if (choice == 9) {
                    useMoveOptionOffer();
                    displayState();
                }
            } while (choice < 1 || choice > 3);
            int startSquareReference = 0;
            while (!squareIsValid) {
                startSquareReference = getSquareReference("containing the piece to move");
                squareIsValid = checkSquareIsValid(startSquareReference, true);
            }
            
            // Displays the board with ^ in the squares that are valid moves
            // START OF ADDED SECTION
            displayBoard(choice, startSquareReference);
            // END OF ADDED SECTION

            
            int finishSquareReference = 0;
            squareIsValid = false;
            while (!squareIsValid) {
                finishSquareReference = getSquareReference("to move to");
                squareIsValid = checkSquareIsValid(finishSquareReference, false);
            }
            boolean moveLegal = currentPlayer.checkPlayerMove(choice, startSquareReference, finishSquareReference);
            if (moveLegal) {
                int pointsForPieceCapture = calculatePieceCapturePoints(finishSquareReference);
                currentPlayer.changeScore(-(choice + (2 * (choice - 1))));
                currentPlayer.updateQueueAfterMove(choice);
                updateboard(startSquareReference, finishSquareReference);
                updatePlayerScore(pointsForPieceCapture);
                Console.writeLine("New score: " + currentPlayer.getScore() + System.lineSeparator());
            }
            if (currentPlayer.sameAs(players.get(0))) {
                currentPlayer = players.get(1);
            } else {
                currentPlayer = players.get(0);
            }
            gameOver = checkIfGameOver();
        }
        displayState();
        displayFinalResult();
    }


Python:

    def __DisplayMove(self, CurrentPlayer, Choice, StartSquareReference):
        #set available squares
        availableMove = Piece("potential",None,0,"^")
        for Row in range(1, self._NoOfRows + 1):
            for Column in range(1, self._NoOfColumns + 1):
                Index = self.__GetIndexOfSquare(Row * 10 + Column)
                if self.__CheckSquareIsValid(Row * 10 + Column, False) and CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, Row * 10 + Column):
                    self._Board[Index].SetPiece(availableMove)
        ##display board
        self.__DisplayBoard()
        #remove ^
        for Row in range(1, self._NoOfRows + 1):
            for Column in range(1, self._NoOfColumns + 1):
                Index = self.__GetIndexOfSquare(Row * 10 + Column)
                if self._Board[Index].GetPieceInSquare() is not None and self._Board[Index].GetPieceInSquare().GetSymbol() =="^":
                    self._Board[Index].SetPiece(None)


    def PlayGame(self):
            ...
            SquareIsValid = False
            self.__DisplayMove(self._CurrentPlayer,Choice,StartSquareReference)
            ...
    
    #~Victor

Any improvements would be appreciated.

VB.NET:

         Sub DisplayPotentialMoves(ByVal Choice As Integer, ByVal SquareReference As Integer, ByVal CurrentPlayer As Player)
           Console.Write(Environment.NewLine & "   ")
           For Column = 1 To NoOfColumns
               Console.Write(Column.ToString() & "  ")
           Next
           Console.Write(Environment.NewLine & "  ")
           For Count = 1 To NoOfColumns
               Console.Write("---")
           Next
           Console.WriteLine("-")
           For Row = 1 To NoOfRows
               Console.Write(Row.ToString() & " ")
               For Column = 1 To NoOfColumns
                   Dim Index As Integer = GetIndexOfSquare(Row * 10 + Column)
                   Console.Write("|" & Board(Index).GetSymbol())
                   Dim PieceInSquare As Piece = Board(Index).GetPieceInSquare()
                   If (CheckSquareIsValid(Row * 10 + Column, False) And CurrentPlayer.CheckPlayerMove(Choice, SquareReference, Row * 10 + Column)) Then
                       Console.Write("^")
                   ElseIf PieceInSquare Is Nothing Then
                       Console.Write(" ")
                   Else
                       Console.Write(PieceInSquare.GetSymbol())
                   End If
               Next
               Console.WriteLine("|")
           Next
           Console.Write("  -")
           For Column = 1 To NoOfColumns
               Console.Write("---")
           Next
           Console.WriteLine()
           Console.WriteLine()
End Sub


Random start queue[edit | edit source]

Description of problem: Randomize the players move queue at the beginning of the game so that the players do not start with the same queue at the beginning of every game.

C#:

// Dastan Class
        private void CreateMoveOptions()
        {
            Players[0].AddToMoveOptionQueue(CreateMoveOption("ryott", 1));
            Players[0].AddToMoveOptionQueue(CreateMoveOption("chowkidar", 1));
            Players[0].AddToMoveOptionQueue(CreateMoveOption("cuirassier", 1));
            Players[0].AddToMoveOptionQueue(CreateMoveOption("faujdar", 1));
            Players[0].AddToMoveOptionQueue(CreateMoveOption("jazair", 1));
            Players[0].AddToMoveOptionQueue(CreateMoveOption("crossMove", 1));
            Players[0].Shuffle();
            Players[1].AddToMoveOptionQueue(CreateMoveOption("ryott", -1));
            Players[1].AddToMoveOptionQueue(CreateMoveOption("chowkidar", -1));
            Players[1].AddToMoveOptionQueue(CreateMoveOption("jazair", -1));
            Players[1].AddToMoveOptionQueue(CreateMoveOption("faujdar", -1));
            Players[1].AddToMoveOptionQueue(CreateMoveOption("cuirassier", -1));
            Players[1].AddToMoveOptionQueue(CreateMoveOption("crossMove", -1));
            Players[1].Shuffle();
        }

        // Player Class
        public void Shuffle()
        {
            Queue.Shuffle();
        }

        // MoveOptionQueue Class
        public void Shuffle()
        {
            Random Rand = new Random();
            int n;
            MoveOption temp;
            for (int i = Queue.Count-1; i > 1; i--)
            {
                n = Rand.Next(0, Queue.Count);
                temp = Queue[n];
                Queue[n] = Queue[i];
                Queue[i] = temp;
            }
        }


Delphi/Pascal:


Java:

    // Dastan Class
    private void createMoveOptions(){
        players.get(0).addToMoveOptionQueue(createMoveOption("ryott", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("chowkidar", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("cuirassier", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("faujdar", 1));
        players.get(0).addToMoveOptionQueue(createMoveOption("jazair", 1));
        players.get(1).addToMoveOptionQueue(createMoveOption("ryott", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("chowkidar", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("jazair", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("faujdar", -1));
        players.get(1).addToMoveOptionQueue(createMoveOption("cuirassier", -1));

        players.get(0).shuffleQueue();
        players.get(1).shuffleQueue();
    }


    // Player Class
    public void shuffleQueue() {
    	// Moves a random item from the queue to the back 1000 times to shuffle it
    	for (int i=0; i<1000; i++) {     
    		Random rand = new Random();
    		int itemToMove = rand.nextInt(5);
    		// moveItemToBack is already a method in the MoveOptionQueue class
    		queue.moveItemToBack(itemToMove);    

    	}
    }


Python:

    def __CreateMoveOptions(self):
        #creates a list of all possible moves
        list = ["ryott","chowkidar","cuirassier","lazzad","jazair"]
        #random.shufflle will randomize the list contents
        random.shuffle(list)
        #the  for loop will iterate through each of the contents of thh list
        for i in list:
            #and will add the moves to the move options
            self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption(i, 1))
            self._Players[1].AddToMoveOptionQueue(self.__CreateMoveOption(i, -1))
            
        #-zednin


VB.NET:

Private Sub CreateMoveOptions()
            Dim RandMove As New Random
            For i = 0 To 1

                Dim MoveList As New List(Of String)
                MoveList.AddRange({"ryott", "chowkidar", "cuirassier", "faujdar", "jazair"})
                Dim d As Integer
                If i = 0 Then
                    d = 1
                Else
                    d = -1
                End If
                While MoveList.Count > 0
                    Dim CurrentString As String = MoveList(RandMove.Next(0, MoveList.Count - 1))
                    Players(i).AddToMoveOptionQueue(CreateMoveOption(CurrentString, d))
                    MoveList.Remove(CurrentString)
                End While
            Next
 End Sub


Choose where to put Kotla and Mirza[edit | edit source]

Description of problem: At the beginning of the game, allow players the option to choose where they place their (Kotla and Mirza) together at the back of their side of the board. For example: Player One can place their Kotla and Mirza between (1,1) to (1,6) and Player Two can place their Kotla and Mirza between (6,1) and (6,6).

C#:


Delphi/Pascal:


Java:

class Dastan {
	public Dastan(int r, int c, int noOfPieces ){
		noOfRows = r;
	    noOfColumns = c;
	    players.add(new Player("Player One", 1, getPieceStartingColumn("Player One")));
	    players.add(new Player("Player Two", -1, getPieceStartingColumn("Player Two")));
	    createMoveOptions();
	    moveOptionOfferPosition = 0;
	    createMoveOptionOffer();
	    createBoard();
	    createPieces(noOfPieces);
	    currentPlayer = players.get(0);
	}
	
	private int getPieceStartingColumn(String playerName) {
		boolean parsed = false;
		int column = 0;
		
		while (!parsed) {
			try {
				Console.writeLine(playerName + " which column (1-6) should your combined Kolta and Mirza start at?: ");
				column = Integer.parseInt(Console.readLine());
				Console.writeLine(noOfRows);
				if (column >= 1 && column <= noOfRows) {
					parsed = true;
				} else {
					Console.writeLine("Please enter a number between 1 and 6, inclusive");
				}
			}
			catch (NumberFormatException e) {
				Console.writeLine("Please enter a number");
			}
		}
		
		return column;
		
	}
		
	private void createBoard() {
	    Square s;
	    board = new ArrayList<>();
	    
	    
	    for (int row = 1; row <= noOfRows; row++) {
	        for (int column = 1; column <= noOfColumns; column++) {
	            if (row == 1 && column == players.get(0).getKoltaColumn()) {
	                s = new Kotla(players.get(0), "K");
	            } else if (row == noOfRows && column == players.get(1).getKoltaColumn()) {
	                s = new Kotla(players.get(1), "k");
	            } else {
	                s = new Square();
	            }
	            board.add(s);
	        }
	    }
	}
	
	private void createPieces(int noOfPieces) {
	    Piece currentPiece;
	    for (int count = 1; count <= noOfPieces; count++) {
	        currentPiece = new Piece("piece", players.get(0), 1, "!");
	        board.get(getIndexOfSquare(2 * 10 + count + 1)).setPiece(currentPiece);
	    }
	    currentPiece = new Piece("mirza", players.get(0), 5, "1");
	    board.get(getIndexOfSquare(10 + players.get(0).getKoltaColumn())).setPiece(currentPiece);
	    for (int count = 1; count <= noOfPieces; count++) {
	        currentPiece = new Piece("piece", players.get(1), 1, "\"");
	        board.get(getIndexOfSquare((noOfRows - 1) * 10 + count + 1)).setPiece(currentPiece);
	    }
	    currentPiece = new Piece("mirza", players.get(1), 5, "2");
	    board.get(getIndexOfSquare(noOfRows * 10 + players.get(1).getKoltaColumn())).setPiece(currentPiece);
	}
	
}

class Player {
	private String name; 
	private int koltaColumn;
	private int direction, score; 
	private MoveOptionQueue queue = new MoveOptionQueue();
	
	public Player(String n, int d, int c) {
	    score = 100;
	    name = n;
	    direction = d;
	    koltaColumn = c;
	}
	
	public int getKoltaColumn() {
		return koltaColumn;
	}
}


Python:

class Player:
    def __init__(self, N, D):
        self.__Score = 100
        self.__Name = N
        self.__Direction = D
        self.__Queue = MoveOptionQueue()
        self.Kotla = int(input(f"Which column should {self.__Name}'s Kotla be?: "))

class Dastan:
    def __CreateBoard(self):
            for Row in range(1, self._NoOfRows + 1):
                for Column in range(1, self._NoOfColumns + 1):
                    if Row == 1 and Column == self._Players[0].Kotla:
                        S = Kotla(self._Players[0], "K")
                    elif Row == self._NoOfRows and Column == self._Players[1].Kotla:
                        S = Kotla(self._Players[1], "k")
                    else:
                        S = Square()
                    self._Board.append(S)

    def __CreatePieces(self, NoOfPieces):
            for Count in range(1, NoOfPieces + 1):
                CurrentPiece = Piece("piece", self._Players[0], 1, "!")
                self._Board[self.__GetIndexOfSquare(2 * 10 + Count + 1)].SetPiece(CurrentPiece)
            CurrentPiece = Piece("mirza", self._Players[0], 5, "1")
            self._Board[self.__GetIndexOfSquare(10 + self._Players[0].Kotla)].SetPiece(CurrentPiece)
            for Count in range(1, NoOfPieces + 1):
                CurrentPiece = Piece("piece", self._Players[1], 1, '"')
                self._Board[self.__GetIndexOfSquare((self._NoOfRows - 1) * 10 + Count + 1)].SetPiece(CurrentPiece)
            CurrentPiece = Piece("mirza", self._Players[1], 5, "2")
            self._Board[self.__GetIndexOfSquare(self._NoOfRows * 10 + (self._Players[1].Kotla))].SetPiece(CurrentPiece)


VB.NET:

          Private Sub CreateBoard()
            Dim S As Square
            Board = New List(Of Square)
            Dim PlayerColumns As New List(Of Integer)
            For i = 0 To 1
                Dim t As Integer
                If i = 0 Then
                    t = 1
                Else
                    t = 6
                End If
                Dim Choice As Integer = -1
                While Choice < 0 Or Choice > 6
                    Console.WriteLine(Players(i).GetName & ", please enter column of where you would like like your kotla and mirza to be placed, it will be placed in row " & t)
                    Choice = Console.ReadLine
                End While

                PlayerColumns.Add(Choice)
            Next
            For Row = 1 To NoOfRows
                For Column = 1 To NoOfColumns
                    If Row = 1 And Column = PlayerColumns(0) Then
                        S = New Kotla(Players(0), "K")
                    ElseIf Row = NoOfRows And Column = PlayerColumns(1) Then
                        S = New Kotla(Players(1), "k")
                    Else
                        S = New Square()
                    End If
                    Board.Add(S)
                Next
            Next
            Dim CurrentPiece As Piece
            CurrentPiece = New Piece("mirza", Players(0), 5, "1")
            Board(GetIndexOfSquare(10 + PlayerColumns(0))).SetPiece(CurrentPiece)
            CurrentPiece = New Piece("mirza", Players(1), 5, "2")
            Board(GetIndexOfSquare(NoOfRows * 10 + PlayerColumns(1))).SetPiece(CurrentPiece)
        End Sub


Move option offer ends turn.[edit | edit source]

Description of problem: Currently, if a player accepts the move option offer (so for example, player 1 takes the jazair offer and replaces the ryott), they then get exactly the same choices again: Choose move option to use from queue (1 to 3) or 9 to take the offer:. This is what the Preliminary Material says will happen "Taking the move option from the offer does not count as a move" ... it is still that player's turn. However, your challenge is to change this, so it DOES count as a turn, and if they choose 9, it goes on to the next player.

C#:


Delphi/Pascal:


Java:


Python:

def PlayGame(self):
        GameOver = False
        while not GameOver:
            self.__DisplayState()
            SquareIsValid = False
            Choice = 0
            while Choice < 1 or Choice > 3:
                Choice = int(input("Choose move option to use from queue (1 to 3) or 9 to take the offer: "))
                if Choice == 9:
                    self.__UseMoveOptionOffer()
                    #---------
                    #put it before to change player before board is displayed again
                    if self._CurrentPlayer.SameAs(self._Players[0]):
                        self._CurrentPlayer = self._Players[1]
                    else:
                        self._CurrentPlayer = self._Players[0]
                    #---------
                    self.__DisplayState()
            while not SquareIsValid:
                StartSquareReference = self.__GetSquareReference("containing the piece to move")
                SquareIsValid = self.__CheckSquareIsValid(StartSquareReference, True)
            SquareIsValid = False
            while not SquareIsValid:
                FinishSquareReference = self.__GetSquareReference("to move to")
                SquareIsValid = self.__CheckSquareIsValid(FinishSquareReference, False)
            MoveLegal = self._CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, FinishSquareReference)
            if MoveLegal:
                PointsForPieceCapture = self.__CalculatePieceCapturePoints(FinishSquareReference)
                self._CurrentPlayer.ChangeScore(-(Choice + (2 * (Choice - 1))))
                self._CurrentPlayer.UpdateQueueAfterMove(Choice)
                self.__UpdateBoard(StartSquareReference, FinishSquareReference)
                self.__UpdatePlayerScore(PointsForPieceCapture)
                print("New score: " + str(self._CurrentPlayer.GetScore()) + "\n")
            if self._CurrentPlayer.SameAs(self._Players[0]):
                self._CurrentPlayer = self._Players[1]
            else:
                self._CurrentPlayer = self._Players[0]
            GameOver = self.__CheckIfGameOver()
        self.__DisplayState()
        self.__DisplayFinalResult()
Cooper and Rhys


VB.NET:


User MoveOption Input Validation[edit | edit source]

Description of problem: Currently you can crash the game when asked to choose "use from queue (1 to 3) or 9 to take the offer" by entering non-integer input.

Validate user input forcing it to be an integer, for choosing 1, 2, 3 or 9, and, if 9 was chosen, for then choosing the move option to replace. A good way to do this is to write a method __ValidateUserInput(PromptString) in the Dastan class, and call this method in PlayGame, passing it the required prompt strings in the two situations where it needs to be called. The method should return the user's input. For now, I would not validate whether it is an appropriate integer, just that it is in fact an integer. To do this you will need to use try ... except ValueError, and a while loop.

C#:


Delphi/Pascal:


Java:

int choice = 0; // setting a default invalid value for the choice

do {

	Console.write("Choose move option to use from queue (1 to 3) or 9 to take the offer: ");

	String input = Console.readLine();
	if (!input.matches("[0-9]")) {  // loops again if the input isn't a single numeric digit
		continue;
	}

	choice = Integer.parseInt(input);
	if (choice == 9) {
		useMoveOptionOffer();
		displayState();
	}


} while (choice < 1 || choice > 3);


Python:

- This fixes any non integer input from crashing the game in all the inputs in the game. - It also makes it so that when you input a wrong number in "Enter the square to move to (row number followed by column number):" to let you put it again until the correct input of the chosen move.

______________________________________________________________________________________________________________________________
   
 def __GetSquareReference(self, Description):
        ###  ADDED  ###
        SelectedSquare = 0
        try:
            SelectedSquare = int(input("Enter the square " + Description + " (row number followed by column number): "))
        except ValueError:
            pass
        ###  END   ###
        return SelectedSquare
______________________________________________________________________________________________________________________________
    
def __UseMoveOptionOffer(self):
        ### ADDED   ###
        val = True
        while val:
            try:
               ReplaceChoice = int(input("Choose the move option from your queue to replace (1 to 5): "))
            except ValueError:
                continue
            if 0 < ReplaceChoice < 6:
                val = False
            else:
                continue
        ###   END   ###
______________________________________________________________________________________________________________________________
    
def PlayGame(self):
        GameOver = False
        while not GameOver:
            self.__DisplayState()
            SquareIsValid = False
            Choice = 0
            while Choice < 1 or Choice > 3:
                ###   ADDED   ###
                try:
                    Choice = int(input("Choose move option to use from queue (1 to 3) or 9 to take the offer: "))
                except ValueError:
                    continue
                ###   END   ###
______________________________________________________________________________________________________________________________
    
def PlayGame(self):
        GameOver = False
        while not GameOver:
        [...]
            while not SquareIsValid:
                FinishSquareReference = self.__GetSquareReference("to move to")
                SquareIsValid = self.__CheckSquareIsValid(FinishSquareReference, False)
                ###   ADDED   ###
                MoveLegal = self._CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, FinishSquareReference)
                if MoveLegal == False:
                    SquareIsValid = False
                else:
                    SquareIsValid = True
                ###   END   ###
______________________________________________________________________________________________________________________________
- If you notice a mistake do fix it and if any improvements can be made, please do so :)


VB.NET:


Create a class that inherits from the Square Class[edit | edit source]

Description of problem: You should also see that the Kotla class has some extra lines in the method GetPointsForOccupancy. The child class can add extra attributes and methods, and can alter existing methods.

This example which is already in the code, could be used to model another subclass. For example a "portal" which automatically moves any piece which goes onto it to a certain point. Or a "booster" square which increases the player's score. I'm not sure what the exam in the summer will ask you to do, but my money is on some kind of new class, based on the Kotla model.

For now, try a "portal" class, which will be placed on square 42 for player 1 and 35 for player 2. Any of the player's own pieces which go to this square should magically move to the other player's mirza and win the game.

C#:

// Add containsPortal method in Square Class
public bool ContainsPortal()
{
    if (Symbol.ToLowerInvariant() == "p")
    {
        return true;
    }
    else
    {
        return false;
    }
}

// Create Portal class inheriting from Square
class Portal : Square
{
    public Portal(Player p, string s)
    {
        BelongsTo = p;
        Symbol = s;
    }
}

// Change Updateboard in DASTAN CLASS
private void UpdateBoard(int startSquareReference, int finishSquareReference)
{
    board[GetIndexOfSquare(finishSquareReference)].SetPiece(board[GetIndexOfSquare(startSquareReference)].RemovePiece());
    // Get square instance as opposed to piece
    Square finishSquare = board[GetIndexOfSquare(finishSquareReference)];

    if (finishSquare.ContainsPortal() && finishSquare.GetBelongsTo().SameAs(currentPlayer))
    {
        // Iterate through each cell to find an opponent player 'mirza' piece
        for (int row = 1; row <= noOfRows; row++)
        {
            for (int col = 1; col <= noOfColumns; col++)
            {
                Piece piece = board[GetIndexOfSquare(row * 10 + col)].GetPieceInSquare();
                if (piece != null && piece.GetTypeOfPiece() == "mirza" && !piece.GetBelongsTo().SameAs(currentPlayer))
                {
                    startSquareReference = finishSquareReference;
                    finishSquareReference = row * 10 + col;
                    // Move piece again, from portal to mirza square
                    board[GetIndexOfSquare(finishSquareReference)].SetPiece(board[GetIndexOfSquare(startSquareReference)].RemovePiece());
                }
            }
        }
    }
}

private void CreateBoard()
{
    Square s;
    board = new List<Square>();
    for (int row = 1; row <= noOfRows; row++)
    {
        for (int column = 1; column <= noOfColumns; column++)
        {
            if (row == 1 && column == noOfColumns / 2)
            {
                s = new Kotla(players[0], "K");
            }
            else if (row == noOfRows && column == noOfColumns / 2 + 1)
            {
                s = new Kotla(players[1], "k");
                // Create portals here
            }
            else if (row == 4 && column == 3)
            {
                s = new Portal(players[0], "P");
            }
            else if (row == 3 && column == 5)
            {
                s = new Portal(players[1], "P");
            }
            else
            {
                s = new Square();
            }
            board.Add(s);
        }
    }
}


Delphi/Pascal:


Java:

// Add containsPortal method in Square Class

   public boolean containsPortal() {
        if (symbol.toLowerCase(Locale.ROOT) == "p") {
            return true;
        } else {
            return false;
        }

    }

// Create Portal class inheriting from Square
class Portal extends Square {
    public Portal(Player p, String s) {
        super();
        belongsTo = p;
        symbol = s;
    }

}
// change Updateboard in DASTAN CLASS
 private void updateboard(int startSquareReference, int finishSquareReference) {
        board.get(getIndexOfSquare(finishSquareReference)).setPiece(board.get(getIndexOfSquare(startSquareReference)).removePiece());
        // get square instance as opposed to piece        
        Square  finishSquare = board.get(getIndexOfSquare(finishSquareReference));
        
        if (finishSquare.containsPortal() && finishSquare.getBelongsTo().sameAs(currentPlayer)) {
            // iterate through each cell to find a oppenent player 'mirza' piece 
            for (int row=1; row <= noOfRows; row++){
                for (int col=1; col <= noOfColumns; col ++) {
                    Piece piece = board.get(getIndexOfSquare(row*10+ col)).getPieceInSquare();
                    if (piece != null && piece.getTypeOfPiece()== "mirza" && !piece.getBelongsTo().sameAs(currentPlayer)) {
                        startSquareReference = finishSquareReference;
                        finishSquareReference = row*10 + col;
                        // move piece again, from portal to mirza square
                        board.get(getIndexOfSquare(finishSquareReference)).setPiece(board.get(getIndexOfSquare(startSquareReference)).removePiece());
                    }
                }
            }
        }

    }
 private void createBoard() {
        Square s;
        board = new ArrayList<>();
        for (int row = 1; row <= noOfRows; row++) {
            for (int column = 1; column <= noOfColumns; column++) {
                if (row == 1 && column == noOfColumns / 2) {
                    s = new Kotla(players.get(0), "K");
                } else if (row == noOfRows && column == noOfColumns / 2 + 1) {
                    s = new Kotla(players.get(1), "k");
                    // create portals here
                } else if (row == 4 && column == 3) {
                    s = new Portal(players.get(0), "P");
                } else if (row == 3 && column == 5) {
                    s = new Portal(players.get(1), "P");
                } else {
                    s = new Square();
                }
                board.add(s);
            }
        }
    }


Python:

______________________________________________________________________________________________________________________________
   
    # Added to Square class
    def ContainsPortal(self):
        if self._Symbol == 'P' or self._Symbol == 'p':
            return True
        else:
            return False
______________________________________________________________________________________________________________________________

class Portal(Square):
    def __init__(self, P, S):
        super(Portal, self).__init__()
        self._BelongsTo = P
        self._Symbol = S

    # No additional methods are needed as all definitions from Square will work here
______________________________________________________________________________________________________________________________

    # In Dastan class
    def __UpdateBoard(self, StartSquareReference, FinishSquareReference):
        # Original movement code
        self._Board[self.__GetIndexOfSquare(FinishSquareReference)].SetPiece(self._Board[self.__GetIndexOfSquare(StartSquareReference)].RemovePiece())
        # Added to handle Portal
        FinishSquare = self._Board[self.__GetIndexOfSquare(FinishSquareReference)]
        if FinishSquare.ContainsPortal() and FinishSquare.GetBelongsTo().SameAs(self._CurrentPlayer):
            for Row in range(1, self._NoOfRows + 1):
                for Column in range(1, self._NoOfColumns + 1):
                    Piece = self._Board[self.__GetIndexOfSquare(Row*10 + Column)].GetPieceInSquare()
                    if Piece is not None and Piece.GetTypeOfPiece() == "mirza" and not Piece.GetBelongsTo().SameAs(self._CurrentPlayer):
                        StartSquareReference = FinishSquareReference
                        FinishSquareReference = Row * 10 + Column
                        # Change player score here as __UpdateBoard is called after checking points for piece capture in PlayGame,
                        # so points for capturing the Mirza wouldn't be awarded otherwise
                        # It's also possible for an opponent's piece to be on your portal, meaning you capture two pieces in one turn
                        # Having this check here means the points for both get added
                        self._CurrentPlayer.ChangeScore(self.__CalculatePieceCapturePoints(FinishSquareReference))
                        # This is also why we move twice, once at the start (moving to the portal) and once here (moving to the opponent's Mirza)
                        self._Board[self.__GetIndexOfSquare(FinishSquareReference)].SetPiece(self._Board[self.__GetIndexOfSquare(StartSquareReference)].RemovePiece())
______________________________________________________________________________________________________________________________

    def __CreateBoard(self):
        for Row in range(1, self._NoOfRows + 1):
            for Column in range(1, self._NoOfColumns + 1):
                if Row == 1 and Column == self._NoOfColumns // 2:
                    S = Kotla(self._Players[0], "K")
                elif Row == self._NoOfRows and Column == self._NoOfColumns // 2 + 1:
                    S = Kotla(self._Players[1], "k")
                # Create portals here
                # I used a symbol of `P` for player 1's and `p` for player 2's
                elif Row == 4 and Column == 2:
                    S = Portal(self._Players[0], 'P')
                elif Row == 3 and Column == 5:
                    S = Portal(self._Players[1], 'p')
                else:
                    S = Square()
                self._Board.append(S)
______________________________________________________________________________________________________________________________


VB.NET:


Potential Questions:

Make the board larger (or allow the user to set the board size).

User help / info / tutorial page.

New class to allow for saving and loading the game.

Limit the number of times the offer option can be taken in a turn.

Undo move option.

Display scores at the end.

Instead of one offer generated, generate three random offers for the user to pick from.

End the game when one person's score reaches 0 or goes negative.[edit | edit source]

C#:

.

Delphi/Pascal:

.

Java:

.

Python:

    def PlayGame(self):
        GameOver = False
        while not GameOver:
            self.__DisplayState()
            SquareIsValid = False
            Choice = 0
            if self._CurrentPlayer.GetScore()<=0: # Here it does the check if the score is below zero while playing the game
              self.__DisplayFinalResult()
              exit()
            while Choice < 1 or Choice > 3:
                if self._CurrentPlayer.GetScore() <=0: #Here it does the check while taking an offer
                  self.__DisplayFinalResult()
                  exit()
                Choice = int(input("Choose move option to use from queue (1 to 3) or 9 to take the offer: "))
                if Choice == 9:
                  self.__UseMoveOptionOffer()
                  self.__DisplayState()
            while not SquareIsValid:
                StartSquareReference = self.__GetSquareReference("containing the piece to move")
                SquareIsValid = self.__CheckSquareIsValid(StartSquareReference, True)
            SquareIsValid = False
            while not SquareIsValid:
                FinishSquareReference = self.__GetSquareReference("to move to")
                SquareIsValid = self.__CheckSquareIsValid(FinishSquareReference, False)
            MoveLegal = self._CurrentPlayer.CheckPlayerMove(Choice, StartSquareReference, FinishSquareReference)
            if MoveLegal:
                PointsForPieceCapture = self.__CalculatePieceCapturePoints(FinishSquareReference)
                self._CurrentPlayer.ChangeScore(-(Choice + (2 * (Choice - 1))))
                self._CurrentPlayer.UpdateQueueAfterMove(Choice)
                self.__UpdateBoard(StartSquareReference, FinishSquareReference)
                self.__UpdatePlayerScore(PointsForPieceCapture)
                print("New score: " + str(self._CurrentPlayer.GetScore()) + "\n")
            if self._CurrentPlayer.SameAs(self._Players[0]):
                self._CurrentPlayer = self._Players[1]
            else:
                self._CurrentPlayer = self._Players[0]
            GameOver = self.__CheckIfGameOver()
        self.__DisplayState()
        self.__DisplayFinalResult()
        #Dimi

.

VB.NET: