You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: PyGamesScripts/Chess Game/README.md
+13-2
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,17 @@
4
4
#### In this game, the whole board can be controlled using simple algebraic commands,
5
5
For example:
6
6
>>>e4 e7
7
-
This will move the pawn present on the e4 position to the e7 position. The program will evaluate constantly, whether its a valid move or not.
7
+
This will move the pawn present on the e4 position to the e7 position. The program will evaluate constantly, whether its a valid move or not.
8
+
9
+
CONVENTIONS: Positions are row-column based, both are numbers from the bottom left. This corresponds to the alpha-number system in traditional chess while being computationally useful. They are specified as tuples
10
+
11
+
Game class contains the following members and methods:
12
+
> Two arrays of pieces for each player.
13
+
> 8x8 piece array with references to these pieces.
14
+
> A parse function, which turns the input from the user into a list of two tuples denoting start and end points.
15
+
> A checkmateExists function which checks if either players are in checkmate.
16
+
> A checkExists function which checks if either players are in check.
17
+
> A main loop, which takes input, runs it through the parser, asks the piece if the move is valid, and moves the piece if it is. If the move conflicts with another piece, that piece is removed. ischeck(mate) is run, and if there is a checkmate, the game prints a message as to who wins.
8
18
9
19
General Chess Rules
10
20
White is always first to move and players take turns alternately moving one piece at a time. A piece may be moved to another position or may capture an opponent´s piece, replacing on its square. With the exception of the knight, a piece may not move over or through any of the other pieces. When a king is threatened with capture (but can protect himself or escape), it´s called check. If a king is in check, then the player must make a move that eliminates the threat of capture and cannot leave the king in check. Checkmate happens when a king is placed in check and there is no legal/valid move to escape. Checkmate ends the game and the side whose king was checkmated looses.
@@ -18,10 +28,11 @@ White is always first to move and players take turns alternately moving one piec
Copy file name to clipboardExpand all lines: PyGamesScripts/Chess Game/chess_game.py
+18-4
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,21 @@
2
2
WHITE="white"
3
3
BLACK="black"
4
4
5
+
"""
6
+
CONVENTIONS: Positions are row-column based, both are numbers from the bottom left. This corresponds to the alpha-number system in traditional chess while being computationally useful. They are specified as tuples
7
+
8
+
Game class contains the following members and methods:
9
+
> Two arrays of pieces for each player.
10
+
> 8x8 piece array with references to these pieces.
11
+
> A parse function, which turns the input from the user into a list of two tuples denoting start and end points.
12
+
> A checkmateExists function which checks if either players are in checkmate.
13
+
> A checkExists function which checks if either players are in check.
14
+
> A main loop, which takes input, runs it through the parser, asks the piece if the move is valid, and moves the piece if it is. If the move conflicts with another piece, that piece is removed. ischeck(mate) is run, and if there is a checkmate, the game prints a message as to who wins.
15
+
"""
16
+
5
17
6
18
classGame:
19
+
# I've decided since the number of pieces is capped but the type of pieces is not (pawn transformations), I've already coded much of the modularity to support just using a dictionary of pieces.
7
20
def__init__(self):
8
21
self.playersturn=BLACK
9
22
self.message="This is where prompts will go"
@@ -64,7 +77,7 @@ def main(self):
64
77
self.message="There is no piece in that space"
65
78
66
79
defisCheck(self):
67
-
# ascertain where the kings are, check all pieces of opposing color against those kings, then if either get hit, check if its checkmate
80
+
# As certain where the kings are, check all pieces of opposing color against those kings, then if either get hit, check if its checkmate
68
81
king=King
69
82
kingDict= {}
70
83
pieceDict= {BLACK: [], WHITE: []}
@@ -80,7 +93,7 @@ def isCheck(self):
80
93
self.message="Black player is in check"
81
94
82
95
defcanSeeKing(self, kingpos, piecelist):
83
-
# checks if any pieces in piece list (which is an array of (piece,position) tuples) can see the king in kingpos
96
+
# Checks if any pieces in piece list (which is an array of (piece,position) tuples) can see the king in kingpos.
0 commit comments