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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
positions are done row-column from the bottom left and are both numbers. This corresponds to the alpha-number system in traditional chess while being computationally useful. they are specified as tuples
"""
importitertools
WHITE="white"
BLACK="black"
classGame:
#ive 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
def__init__(self):
self.playersturn=BLACK
self.message="this is where prompts will go"
self.gameboard= {}
self.placePieces()
print("chess program. enter moves in algebraic notation separated by space")
if type(arg[0]) is not type(1) or type(arg[1]) is not type(1):
return False
return True"""
defprintBoard(self):
print(" 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |")
foriinrange(0,8):
print("-"*32)
print(chr(i+97),end="|")
forjinrange(0,8):
item=self.gameboard.get((i,j)," ")
print(str(item)+' |', end=" ")
print()
print("-"*32)
"""game class. contains the following members and methods:
two arrays of pieces for each player
8x8 piece array with references to these pieces
a parse function, which turns the input from the user into a list of two tuples denoting start and end points
a checkmateExists function which checks if either players are in checkmate
a checkExists function which checks if either players are in check (woah, I just got that nonsequitur)
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
if (x+1,y+self.direction) ingameboardandself.noConflict(gameboard, Color, x+1, y+self.direction) : answers.append((x+1,y+self.direction))
if (x-1,y+self.direction) ingameboardandself.noConflict(gameboard, Color, x-1, y+self.direction) : answers.append((x-1,y+self.direction))
if (x,y+self.direction) notingameboardandColor==self.Color : answers.append((x,y+self.direction))# the condition after the and is to make sure the non-capturing movement (the only fucking one in the game) is not used in the calculation of checkmate