0% found this document useful (0 votes)
2 views19 pages

Python Dastan Game Programming Tasks

Uploaded by

harryazaan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views19 pages

Python Dastan Game Programming Tasks

Uploaded by

harryazaan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Programming Tasks

These questions require you to load the Skeleton Program and to make programming changes to it.

Note that any alternative or additional code changes that you deemed appropriate to make must also be evidenced

– ensuring that it is clear where in the Skeleton Program those changes have been made.

Important: Throughout this document and the Python code, methods are referred to as private, protected and
public. In this document, method names are written without leading underscores, whereas in the Python code,
method names are written with leading underscores; a private method appears with a double underscore at the
start and a protected method with a single underscore.

Task 1

Task 1 Marks: 2
This question refers to the Dastan class.

Introduce new functionality at the point at which both players are instantiated that allows players to have
custom names set by the users. Ensure that players cannot both have the same name. This code will
replace the two lines in the constructor that currently create the players with a single call to a new private
method, CreateCustomPlayers.

What you need to do

Task 1

Create a new method CreateCustomPlayers in the Dastan class. Allow the user to enter custom
names for each player. Include checks in your code to ensure that two players cannot have the same
custom name.

Allow the first player to enter any name they like, then repeatedly ask the user for the second player
name until they are both different.

Task 2

Test that the changes you have made work:

● run the skeleton program.


● enter ‘Tom’ as the first player name and then enter ‘Tom’ as the second player name, when re-
prompted, enter ‘Tom’ again and then at the next prompt, enter ‘Victoria’.
● show the game using one of the custom names to address the player in the main game menu.

Evidence that you need to provide:


 PROGRAM SOURCE CODE showing creation of a new CreateCustomPlayers method in the
Dastan class
 SCREEN CAPTURE(S) showing the required test
AQA 2023: Dastan (Python) Page 1 of 19 © ZigZag Education, 2022
Source code:

def CreateCustomPlayers(self, playerIdx=0):


if playerIdx >= self._NumPlayers:
return

while True:
playerName = input(f"Enter the name of player {playerIdx + 1}:
").strip()

if playerName == "":
continue

self._Players[playerIdx] = Player(playerName, (-1)**(playerIdx % 2))


break

[Link](playerIdx + 1)

Screen capture(s):

AQA 2023: Dastan (Python) Page 2 of 19 © ZigZag Education, 2022


Task 2

Task 2 Marks: 4
This question refers to the CreateMoveOptionOffer, CreateMoveOption and CreateMoveOptions
methods and creation of a new method CreateFarisMoveOption in the Dastan class.

Develop a new move option called a ‘Faris’ (Knight). The Faris move option moves similarly to a knight in
chess – either two squares forward/backwards and one square left/right or oppositely two squares
left/right and one square forward/backwards. You should demonstrate the use of the Direction
parameter.

What you need to do

Task 1

i) Add new functionality into the


CreateMoveOptionOffer & CreateMoveOption
methods to perform a Faris move.

ii) Modify the CreateMoveOptions method to add the


Faris after the Ryott for both players.

AQA 2023: Dastan (Python) Page 3 of 19 © ZigZag Education, 2022


iii) Create a new method CreateFarisMoveOption which
adds moves using the pattern shown, to the
NewMoveOption object.

Task 2

Test that the changes you have made work:

● run the skeleton program.


● play two turns, showing both players making legal Faris moves.

Evidence that you need to provide:

 PROGRAM SOURCE CODE showing changes made to the CreateNewOptionOffer,


CreateMoveOption and CreateMoveOptions methods
 PROGRAM SOURCE CODE showing a new method CreateFarisMoveOption
 SCREEN CAPTURE(S) showing the required test

Source code:

def __CreateFarisMoveOption(self, Direction: int):


NewMoveOption = MoveOption("faris")
NewMove = Move(2 * Direction, 1 * Direction)
[Link](NewMove)
NewMove = Move(2 * Direction, -1 * Direction)
[Link](NewMove)
NewMove = Move(1 * Direction, 2 * Direction)
[Link](NewMove)
NewMove = Move(1 * Direction, -2 * Direction)
[Link](NewMove)
NewMove = Move(-1 * Direction, 2 * Direction)
[Link](NewMove)
NewMove = Move(-1 * Direction, -2 * Direction)
[Link](NewMove)
NewMove = Move(-2 * Direction, -1 * Direction)
[Link](NewMove)
NewMove = Move(-2 * Direction, 1 * Direction)
[Link](NewMove)
return NewMoveOption

Screen capture(s):

AQA 2023: Dastan (Python) Page 4 of 19 © ZigZag Education, 2022


AQA 2023: Dastan (Python) Page 5 of 19 © ZigZag Education, 2022
AQA 2023: Dastan (Python) Page 6 of 19 © ZigZag Education, 2022
Task 3

Task 3 Marks: 4
Develop a new move option called a ‘Sarukh’ (Rocket). The Sarukh move option moves forward in a
rocket shape. You should demonstrate the use of the Direction parameter.

What you need to do

Task 1

i) Add new functionality into the CreateMoveOptionOffer,


CreateMoveOption and CreateMoveOptions methods
to perform a Sarukh move.

ii) Modify the CreateMoveOptions method to add the


Sarukh after the Ryott for both players.

iii) Create a new method CreateSarukhMoveOption which


adds moves using the pattern below, to the new
MoveOption object. The pattern is shown from the
viewpoint of player two. For player one, the layout is
inverted.

Task 2

Test that the changes you have made work:

● run the skeleton program.


● play two turns, showing both players making legal Sarukh moves.

Evidence that you need to provide:


 PROGRAM SOURCE CODE showing changes made to the CreateMoveOptionOffer,
CreateMoveOption and CreateMoveOptions methods
 PROGRAM SOURCE CODE showing a new method CreateSarukhMoveOption
 SCREEN CAPTURE(S) showing the required test

Source code:

def __CreateMoveOptionOffer(self):
"""
It creates a list of strings and appends the strings "jazair",
"chowkidar", "cuirassier", "ryott", and "faujdar" to it
"""
self._MoveOptionOffer.append("faris")
self._MoveOptionOffer.append("sarukh")
self._MoveOptionOffer.append("jazair")

AQA 2023: Dastan (Python) Page 7 of 19 © ZigZag Education, 2022


self._MoveOptionOffer.append("chowkidar")
self._MoveOptionOffer.append("cuirassier")
self._MoveOptionOffer.append("ryott")
self._MoveOptionOffer.append("faujdar")

def __CreateMoveOption(self, Name: str, Direction: int):


"""
It creates a list of all possible moves for a given piece, given a
direction.

:param Name: The name of the piece


:type Name: str
:param Direction: 0 = Up, 1 = Right, 2 = Down, 3 = Left
:type Direction: int
:return: A list of tuples.
"""
if 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)
elif Name == "faris":
return self.__CreateFarisMoveOption(Direction)
elif Name == "sarukh":
return self.__CreateSarukhMoveOption(Direction)
else:
return self.__CreateCuirassierMoveOption(Direction)

def __CreateMoveOptions(self):
"""
It creates a list of move options for each player.
"""

self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("ryott", 1))

self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("sarukh", 1))

self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("faris", 1))

self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("chowkidar",
1))

self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("cuirassier",
1))

AQA 2023: Dastan (Python) Page 8 of 19 © ZigZag Education, 2022


self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("faujdar", 1))

self._Players[0].AddToMoveOptionQueue(self.__CreateMoveOption("jazair", 1))

self._Players[1].AddToMoveOptionQueue(self.__CreateMoveOption("ryott", -1))

self._Players[1].AddToMoveOptionQueue(self.__CreateMoveOption("sarukh", -1))

self._Players[1].AddToMoveOptionQueue(self.__CreateMoveOption("faris", -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))

def __CreateSarukhMoveOption(self, Direction: int):


NewMoveOption = MoveOption("sarukh")
NewMove = Move(2 * Direction, 0)
[Link](NewMove)
NewMove = Move(1 * Direction, 1)
[Link](NewMove)
NewMove = Move(1 * Direction, -1)
[Link](NewMove)
NewMove = Move(0, 1)
[Link](NewMove)
NewMove = Move(0, -1)
[Link](NewMove)
return NewMoveOption

Screen capture(s):

AQA 2023: Dastan (Python) Page 9 of 19 © ZigZag Education, 2022


AQA 2023: Dastan (Python) Page 10 of 19 © ZigZag Education, 2022
Task 4

Task 4 Marks: 5
This question refers to the PlayGame method in the Dastan class and creation of a new method
AwardWafr in the Dastan class, GetWafrAwarded and SetWafrAwarded together with one new
attribute WafrAwarded in the Player class.

Create a ‘Wafr’ (abundance) award which can be applied to either player once per game. The ‘Wafr’ has
a 25% chance of being awarded to a player on their turn. On receipt of the ‘Wafr’, the player has the
option of ANY move from their move queue rather than just being able to select from the first three items.
The ‘Wafr’ award removes the move cost for the move the player selects for that turn.

Note: If the player makes an invalid move then they ‘lose’ their Wafr and get no value from it. Also the
player should not be able to ‘take the offer’ if a Wafr is awarded.

What you need to do

Task 1

i) Create a new method in the Dastan class called AwardWafr. This method should have a 25%
chance of returning true.
ii) Add a new private attribute to the Player class called WafrAwarded. Include accessor and
mutator (getter/setter) methods for this attribute.

Task 2

Update the PlayGame method in the Dastan class to call the new AwardWafr method. If the player
hasn’t already been awarded a Wafr, print out a message saying ‘You have been awarded a Wafr, you
can select any move from your queue for free this turn.’ Adjust the input range to allow any move option
in the queue to be selected. Ensure that there is no score adjustment for playing a move, and update the
value of the attribute to ensure that they cannot receive another Wafr.

Task 3

Test that the changes you have made work:

● run the skeleton program.


● play the game to show a player being awarded a Wafr.
● play a move option from position 4 or 5 in the move option queue.
● show the updated board and correctly modified score.

Evidence that you need to provide:


 PROGRAM SOURCE CODE showing changes made to the PlayGame method of the Dastan
class, creation of a new method AwardWafr in the Dastan class
d PROGRAM SOURCE CODE showing changes made to the Player class and creation of the new
methods GetWafrAwarded, SetWafrAwarded together with one new attribute WafrAwarded
 SCREEN CAPTURE(S) showing the required test

AQA 2023: Dastan (Python) Page 11 of 19 © ZigZag Education, 2022


Source code:

def PlayGame(self):
GameOver = False
while not GameOver:
self.__DisplayState()
SquareIsValid = False

# wafr stuff
wafrAwarded = [Link]()

# if the player has received a wafr for the first time


if not self._CurrentPlayer.Wafr and wafrAwarded:
print("You have been awarded a Wafr, you can select any move
from your queue for free this turn.")
# if the player has already had a wafr before then don't award it
again
elif self._CurrentPlayer.Wafr and wafrAwarded:
wafrAwarded = False

Choice = 0
while Choice < 1 or (Choice > 5 if wafrAwarded else Choice > 3):
Choice = int(
input(
"Choose move option to use from queue (1 to 3), 8 to
peek at your opponent's queue or 9 to take the offer: "
)
)

if Choice == 8:
usePlayer = [player for player in self._Players if not
self._CurrentPlayer.SameAs(player)][0]
print([Link]())
self._CurrentPlayer.ChangeScore(-5)
print("That move costed 5 points.")
print(f"Score: {self._CurrentPlayer.GetScore()}")

elif Choice == 9:
self.__UseMoveOptionOffer()
self.__DisplayState()

while not SquareIsValid:


StartSquareReference = self.__GetSquareReference(
"containing the piece to move"
)
SquareIsValid =
self.__CheckSquareIsValid(StartSquareReference, True)

AQA 2023: Dastan (Python) Page 12 of 19 © ZigZag Education, 2022


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
)

# make it so that the player will never receive a wafr again


if wafrAwarded:
self._CurrentPlayer.Wafr = True
# otherwise if there has been no wafr then just change the
score as normal
elif not wafrAwarded:
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 AwardWafr(self):
return [Link]([0, 1, 2, 3]) == 0

def __init__(self, N: str, D: int):


self.__Score = 100
self.__Name = N
self.__Direction = D
self.__Queue = MoveOptionQueue()
self.__WafrAwarded = False

AQA 2023: Dastan (Python) Page 13 of 19 © ZigZag Education, 2022


@property
def Wafr(self):
return self.__WafrAwarded

@[Link]
def Wafr(self, value):
self.__WafrAwarded = value

Screen capture(s):

AQA 2023: Dastan (Python) Page 14 of 19 © ZigZag Education, 2022


Task 5

Task 5 Marks: 5
This question refers to the PlayGame method in the Dastan class and the creation of a new method
GetJustQueue in the Player class.

Introduce a new option 8 to the main game playing menu. On selecting this option, a player can look at
their opponent’s queue to spy what move options their opponent might be considering next. Spying on
an opponent’s queue, however, carries a cost of 5 points from the player’s score. After spying on an
opponent’s queue, the player’s turn should continue as normal.

What you need to do

Task 1

Create a new method in the Player class called GetJustQueue which uses the GetQueueAsString
method to return a string version of just the player’s queue.

Task 2

Modify the PlayGame method to introduce new functionality which adds a new option 8 to the main
game playing menu. If the user selects this option, display the move option queue for the opposing
player.
(Hint: You can check the current player using the SameAs method and then pick the other player.)
Subtract 5 from the current player score and display the game state again allowing the player to continue
their turn as normal.

Task 3

Test that the changes you have made work:

● run the skeleton program.


● show player one selecting option 8 from the main game menu.
● show the opponent queue being displayed clearly on the screen and the player one score
reducing by 5 points.

Evidence that you need to provide:


 PROGRAM SOURCE CODE showing changes made to the PlayGame method and of the Dastan
class
 PROGRAM SOURCE CODE showing new method GetJustQueue in the Player class
 SCREEN CAPTURE(S) showing the required test

Source code:

def PlayGame(self):
GameOver = False
while not GameOver:
self.__DisplayState()

AQA 2023: Dastan (Python) Page 15 of 19 © ZigZag Education, 2022


SquareIsValid = False

# wafr stuff
wafrAwarded = [Link]()

# if the player has received a wafr for the first time


if not self._CurrentPlayer.Wafr and wafrAwarded:
print("You have been awarded a Wafr, you can select any move
from your queue for free this turn.")
# if the player has already had a wafr before then don't award it
again
elif self._CurrentPlayer.Wafr and wafrAwarded:
wafrAwarded = False

Choice = 0
while Choice < 1 or (Choice > 5 if wafrAwarded else Choice > 3):
Choice = int(
input(
"Choose move option to use from queue (1 to 3), 8 to
peek at your opponent's queue or 9 to take the offer: "
)
)

if Choice == 8:
usePlayer = [player for player in self._Players if not
self._CurrentPlayer.SameAs(player)][0]
print([Link]())
self._CurrentPlayer.ChangeScore(-5)
print("That move costed 5 points.")
print(f"Score: {self._CurrentPlayer.GetScore()}")

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:
FinishSquareReference = self.__GetSquareReference("to move
to")
SquareIsValid =
self.__CheckSquareIsValid(FinishSquareReference, False)

AQA 2023: Dastan (Python) Page 16 of 19 © ZigZag Education, 2022


MoveLegal = self._CurrentPlayer.CheckPlayerMove(
Choice, StartSquareReference, FinishSquareReference
)
if MoveLegal:
PointsForPieceCapture = self.__CalculatePieceCapturePoints(
FinishSquareReference
)

# make it so that the player will never receive a wafr again


if wafrAwarded:
self._CurrentPlayer.Wafr = True
# otherwise if there has been no wafr then just change the
score as normal
elif not wafrAwarded:
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 GetJustQueue(self):
return self.__Queue.GetQueueAsString()

Screen capture(s):

AQA 2023: Dastan (Python) Page 17 of 19 © ZigZag Education, 2022


AQA 2023: Dastan (Python) Page 18 of 19 © ZigZag Education, 2022
Task 6

AQA 2023: Dastan (Python) Page 19 of 19 © ZigZag Education, 2022

You might also like