profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/neery1218/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.

daniel5151/ts7200 9

A high-level emulator for the TS-7200 Single Board Computer, as used in CS 452 - Real-Time Programming at the University of Waterloo

neery1218/Kamisado 2

A board game for Android (work in progress)

neery1218/PythonOFCSimulator 1

Late game EV solver for Pineapple oFC

neery1218/Blokus 0

Blokus is an abstract strategy board game for two to four players, invented by Bernard Tavitian and first released in 2000 by Sekkoïa, a French company.

neery1218/Bot 0

works with neery1218/OFCSolver to try and play OFC on the PokerBros app

create barnchneery1218/chess-js

branch : typescript

created branch time in 2 days

push eventneery1218/chess

neery1218

commit sha bafc9480e2bd223626485b40dc8ea5b68b1da93a

Update README.md

view details

push time in 9 days

push eventneery1218/chess

Janujan Sritharan

commit sha 32a521aa7dd6ee3602bf9296a446f55301d15424

Added move functionality for board other than castling

view details

Janujan Sritharan

commit sha 76054d870a6d574e9f90c6dc82977dd794d9be5d

Castling works now

view details

Janujan Sritharan

commit sha 23d30281ead198c43ec3d8fd0d88bfb391b38502

Implemented promoting

view details

Janujan Sritharan

commit sha 1de4f260720c54d45a162eb6e2198b45b8d006c8

Just adding all new testing boards

view details

Janujan Sritharan

commit sha 89760b9c440bc2c7957e856dae1e0e97809c80b1

Added stalemate function

view details

Janujan Sritharan

commit sha bbabf5ee4c400f341f517fe492a21a00569dc8ee

Everything works now. Also auto-formatted

view details

Janujan Sritharan

commit sha d83e82dc3df37ee8215e60c3e351995aec1da0b2

Addressed comments in pull request. See comments for reasoning.

view details

Janujan Sritharan

commit sha 31bb57346e67eb9c6d70d3c6247374a1d1833e76

Changed name from include_castle_moves to exclude_castle_moves

view details

neery1218

commit sha 53a2bbdb4d9b25f10b7a4d8dc3813d8489c6f70b

Merge pull request #3 from janujan99/main Added everything except main loop

view details

push time in 9 days

PR merged neery1218/chess

Added everything except main loop

Stalemate, checkmate, and filter_moves implemented. Infrastructure in place to finish main loop.

+432 -34

0 comment

13 changed files

janujan99

pr closed time in 9 days

Pull request review commentneery1218/chess

Added everything except main loop

 def __init__(self, x: int, y: int, colour: Enum, has_moved=False):         super().__init__(x, y, colour)         self.letter = "♔" if colour == Colour.BLACK else "♚" -    def get_valid_moves(self, board, last_moved: str, initial_pos: tuple, final_pos: tuple):+    def get_valid_moves(self, board, last_moved: str, initial_pos: tuple, final_pos: tuple, include_castle_moves=False):         x = self.x         y = self.y -        all_squares = [(x-1, y-1), (x, y-1), (x+1, y-1), (x-1, y),-                       (x+1, y), (x-1, y+1), (x, y+1), (x+1, y+1)]+        moves_on_board = [(x-1, y-1), (x, y-1), (x+1, y-1), (x-1, y),+                          (x+1, y), (x-1, y+1), (x, y+1), (x+1, y+1)]+         possible_moves = [-            square for square in all_squares if self.on_board(square)]-        return possible_moves+            square for square in moves_on_board if self.on_board(square)]++        valid_moves = [move for move in possible_moves if (+            not move in board.board_dict) or (board.board_dict[move].colour != self.colour)]++        if not include_castle_moves:

uh, so if "not include_castle_moves", we include castle moves?

janujan99

comment created time in 16 days

PullRequestReviewEvent

Pull request review commentneery1218/chess

Added everything except main loop

 def __init__(self, x: int, y: int, colour: Enum, has_moved=False):         super().__init__(x, y, colour)         self.letter = "♔" if colour == Colour.BLACK else "♚" -    def get_valid_moves(self, board, last_moved: str, initial_pos: tuple, final_pos: tuple):+    def get_valid_moves(self, board, last_moved: str, initial_pos: tuple, final_pos: tuple, scanning_board=False):         x = self.x         y = self.y -        all_squares = [(x-1, y-1), (x, y-1), (x+1, y-1), (x-1, y),+        moves_on_board = [(x-1, y-1), (x, y-1), (x+1, y-1), (x-1, y),                        (x+1, y), (x-1, y+1), (x, y+1), (x+1, y+1)]-        possible_moves = [-            square for square in all_squares if self.on_board(square)]-        return possible_moves+        +        possible_moves = [square for square in moves_on_board if self.on_board(square)]++        valid_moves = [move for move in possible_moves if (not move in board.board_dict) or (board.board_dict[move].colour != self.colour)]+        +        if not scanning_board:+            castles = self.can_castle(board)+            if castles[0]:+                valid_moves.append(("Queenside",))+            if castles[1]:+                valid_moves.append(("Kingside",))++        return valid_moves++    def can_castle(self, board):+        # if king has moved return False+        if self.has_moved:+            return (False, False)++        queenside = True+        kingside = True+        rank = 0 if self.colour == Colour.BLACK else 7+        # if the queenside rook is no longer in its original place (captured or moved), or it moved but returned back there, or another piece is there instead, queenside castle is not possible+        if (not (0, rank) in board.board_dict) or board.board_dict[(0, rank)].has_moved:+            queenside = False+        # if the kingside rook is no longer in its original place (captured or moved), or it moved but returned back there, or another piece is there instead, kingside castle is not possible+        if (not (7, rank) in board.board_dict) or board.board_dict[(7, rank)].has_moved:+            kingside = False+        # if there are pieces in between king and queenside rook, then queenside castle is also not possible+        in_btwn_queenside = [(1, rank), (2, rank), (3, rank)]+        for square in in_btwn_queenside:+            if square in board.board_dict:+                queenside = False+        # if there are pieces in between king and kingside rook, then kingside castle is also not possible+        in_btwn_kingside = [(5, rank), (6, rank)]+        for square in in_btwn_kingside:+            if square in board.board_dict:+                kingside = False+        # for every opposing coloured piece, check if the squares in between the king and queenside rook (including the king) are in them+        # if they are, then queenside castle is not possible+        in_btwn_queenside.append((self.x, self.y))+        for piece in board.board_dict:+            if board.board_dict[piece].colour != self.colour:+                moves = board.board_dict[piece].get_valid_moves(

general: when using get_valid_moves, i would use the key word argument for scanning_board, eg: get_valid_moves( a, b, c, scanning_board=True)

janujan99

comment created time in 18 days

PullRequestReviewEvent

Pull request review commentneery1218/chess

Added everything except main loop

 def __init__(self, x: int, y: int, colour: Enum, has_moved=False):         super().__init__(x, y, colour)         self.letter = "♔" if colour == Colour.BLACK else "♚" -    def get_valid_moves(self, board, last_moved: str, initial_pos: tuple, final_pos: tuple):+    def get_valid_moves(self, board, last_moved: str, initial_pos: tuple, final_pos: tuple, scanning_board=False):

i think a better name for scanning_board is "include_castle_moves"

janujan99

comment created time in 18 days

Pull request review commentneery1218/chess

Added everything except main loop

 def in_check(self, colour: Enum):             if self.board_dict[piece].letter == letter and self.board_dict[piece].colour == colour:                 king_posn = piece -        #get copy of board+        # get copy of board         copy_board = self.deepcopy()-        #search for king's position in opposing colour pieces+        # search for king's position in opposing colour pieces         for piece in self.board_dict:-            if self.board_dict[piece].colour != colour and king_posn in self.board_dict[piece].get_valid_moves(copy_board, self.last_moved, self.initial_pos, self.final_pos):+            if self.board_dict[piece].colour != colour and king_posn in self.board_dict[piece].get_valid_moves(copy_board, self.last_moved, self.initial_pos, self.final_pos, True):                 return True         return False +    def make_move(self, piece_location: tuple, move_location: tuple) -> None:+        if len(move_location) == 2:

i would add a comment here indicating "regular move"

janujan99

comment created time in 18 days

Pull request review commentneery1218/chess

Added everything except main loop

 def __init__(self, x: int, y: int, colour: Enum, has_moved=False):         super().__init__(x, y, colour)         self.letter = "♔" if colour == Colour.BLACK else "♚" -    def get_valid_moves(self, board, last_moved: str, initial_pos: tuple, final_pos: tuple):+    def get_valid_moves(self, board, last_moved: str, initial_pos: tuple, final_pos: tuple, scanning_board=False):         x = self.x         y = self.y -        all_squares = [(x-1, y-1), (x, y-1), (x+1, y-1), (x-1, y),+        moves_on_board = [(x-1, y-1), (x, y-1), (x+1, y-1), (x-1, y),                        (x+1, y), (x-1, y+1), (x, y+1), (x+1, y+1)]-        possible_moves = [-            square for square in all_squares if self.on_board(square)]-        return possible_moves+        +        possible_moves = [square for square in moves_on_board if self.on_board(square)]++        valid_moves = [move for move in possible_moves if (not move in board.board_dict) or (board.board_dict[move].colour != self.colour)]+        +        if not scanning_board:+            castles = self.can_castle(board)+            if castles[0]:+                valid_moves.append(("Queenside",))+            if castles[1]:+                valid_moves.append(("Kingside",))++        return valid_moves++    def can_castle(self, board):

python supports returning multiple values, i would do that instead of returning a tuple. then: can_kingside, can_queenside = can_castle(board)

janujan99

comment created time in 18 days

Pull request review commentneery1218/chess

Added everything except main loop

 def in_check(self, colour: Enum):             if self.board_dict[piece].letter == letter and self.board_dict[piece].colour == colour:                 king_posn = piece -        #get copy of board+        # get copy of board         copy_board = self.deepcopy()-        #search for king's position in opposing colour pieces+        # search for king's position in opposing colour pieces         for piece in self.board_dict:-            if self.board_dict[piece].colour != colour and king_posn in self.board_dict[piece].get_valid_moves(copy_board, self.last_moved, self.initial_pos, self.final_pos):+            if self.board_dict[piece].colour != colour and king_posn in self.board_dict[piece].get_valid_moves(copy_board, self.last_moved, self.initial_pos, self.final_pos, True):                 return True         return False +    def make_move(self, piece_location: tuple, move_location: tuple) -> None:+        if len(move_location) == 2:+            moved_piece = self.board_dict[piece_location].deepcopy()+            del self.board_dict[piece_location]+            moved_piece.x = move_location[0]+            moved_piece.y = move_location[1]+            moved_piece.has_moved = True+            self.board_dict[move_location] = moved_piece+            #promote piece if moved piece is a pawn and it reached the end+            if (self.board_dict[move_location].letter == "♙" and move_location[1] == 7) or (self.board_dict[move_location].letter == "♟︎" and move_location[1] == 0):+                self.promote(move_location)+        elif len(move_location) == 3:

en passant? add comment here too

janujan99

comment created time in 18 days

Pull request review commentneery1218/chess

Added everything except main loop

 def __init__(self, x: int, y: int, colour: Enum, has_moved=False):         super().__init__(x, y, colour)         self.letter = "♔" if colour == Colour.BLACK else "♚" -    def get_valid_moves(self, board, last_moved: str, initial_pos: tuple, final_pos: tuple):+    def get_valid_moves(self, board, last_moved: str, initial_pos: tuple, final_pos: tuple, scanning_board=False):         x = self.x         y = self.y -        all_squares = [(x-1, y-1), (x, y-1), (x+1, y-1), (x-1, y),+        moves_on_board = [(x-1, y-1), (x, y-1), (x+1, y-1), (x-1, y),                        (x+1, y), (x-1, y+1), (x, y+1), (x+1, y+1)]-        possible_moves = [-            square for square in all_squares if self.on_board(square)]-        return possible_moves+        +        possible_moves = [square for square in moves_on_board if self.on_board(square)]++        valid_moves = [move for move in possible_moves if (not move in board.board_dict) or (board.board_dict[move].colour != self.colour)]+        +        if not scanning_board:+            castles = self.can_castle(board)+            if castles[0]:+                valid_moves.append(("Queenside",))+            if castles[1]:+                valid_moves.append(("Kingside",))++        return valid_moves++    def can_castle(self, board):+        # if king has moved return False+        if self.has_moved:+            return (False, False)++        queenside = True+        kingside = True+        rank = 0 if self.colour == Colour.BLACK else 7+        # if the queenside rook is no longer in its original place (captured or moved), or it moved but returned back there, or another piece is there instead, queenside castle is not possible+        if (not (0, rank) in board.board_dict) or board.board_dict[(0, rank)].has_moved:+            queenside = False+        # if the kingside rook is no longer in its original place (captured or moved), or it moved but returned back there, or another piece is there instead, kingside castle is not possible+        if (not (7, rank) in board.board_dict) or board.board_dict[(7, rank)].has_moved:+            kingside = False+        # if there are pieces in between king and queenside rook, then queenside castle is also not possible+        in_btwn_queenside = [(1, rank), (2, rank), (3, rank)]+        for square in in_btwn_queenside:+            if square in board.board_dict:+                queenside = False+        # if there are pieces in between king and kingside rook, then kingside castle is also not possible+        in_btwn_kingside = [(5, rank), (6, rank)]+        for square in in_btwn_kingside:+            if square in board.board_dict:+                kingside = False+        # for every opposing coloured piece, check if the squares in between the king and queenside rook (including the king) are in them+        # if they are, then queenside castle is not possible+        in_btwn_queenside.append((self.x, self.y))

is this correct? aren't there more squares?

janujan99

comment created time in 18 days

Pull request review commentneery1218/chess

Added everything except main loop

 def __init__(self, x: int, y: int, colour: Enum, has_moved=False):         super().__init__(x, y, colour)         self.letter = "♔" if colour == Colour.BLACK else "♚" -    def get_valid_moves(self, board, last_moved: str, initial_pos: tuple, final_pos: tuple):+    def get_valid_moves(self, board, last_moved: str, initial_pos: tuple, final_pos: tuple, scanning_board=False):         x = self.x         y = self.y -        all_squares = [(x-1, y-1), (x, y-1), (x+1, y-1), (x-1, y),+        moves_on_board = [(x-1, y-1), (x, y-1), (x+1, y-1), (x-1, y),                        (x+1, y), (x-1, y+1), (x, y+1), (x+1, y+1)]-        possible_moves = [-            square for square in all_squares if self.on_board(square)]-        return possible_moves+        +        possible_moves = [square for square in moves_on_board if self.on_board(square)]++        valid_moves = [move for move in possible_moves if (not move in board.board_dict) or (board.board_dict[move].colour != self.colour)]+        +        if not scanning_board:+            castles = self.can_castle(board)+            if castles[0]:+                valid_moves.append(("Queenside",))+            if castles[1]:+                valid_moves.append(("Kingside",))++        return valid_moves++    def can_castle(self, board):+        # if king has moved return False+        if self.has_moved:+            return (False, False)++        queenside = True+        kingside = True+        rank = 0 if self.colour == Colour.BLACK else 7+        # if the queenside rook is no longer in its original place (captured or moved), or it moved but returned back there, or another piece is there instead, queenside castle is not possible+        if (not (0, rank) in board.board_dict) or board.board_dict[(0, rank)].has_moved:+            queenside = False+        # if the kingside rook is no longer in its original place (captured or moved), or it moved but returned back there, or another piece is there instead, kingside castle is not possible+        if (not (7, rank) in board.board_dict) or board.board_dict[(7, rank)].has_moved:+            kingside = False+        # if there are pieces in between king and queenside rook, then queenside castle is also not possible+        in_btwn_queenside = [(1, rank), (2, rank), (3, rank)]+        for square in in_btwn_queenside:+            if square in board.board_dict:+                queenside = False+        # if there are pieces in between king and kingside rook, then kingside castle is also not possible+        in_btwn_kingside = [(5, rank), (6, rank)]+        for square in in_btwn_kingside:+            if square in board.board_dict:+                kingside = False+        # for every opposing coloured piece, check if the squares in between the king and queenside rook (including the king) are in them

weird comment. you mean the squares in between the rook and king can't be attacked by opposing pieces?

janujan99

comment created time in 18 days

PullRequestReviewEvent

push eventneery1218/chess-js

neerajensritharan

commit sha a2e4a702dde8540fd6a5bacc0a7f598bd7614a10

prettier

view details

push time in a month

push eventneery1218/chess-js

neerajensritharan

commit sha d29f4988c1a464dc6b766df03424a47cdc104e71

implementing stalemate + other bug fixes

view details

push time in a month

push eventneery1218/chess-js

neerajensritharan

commit sha 6ec730fe91053e9fb777218b39cc245e72d35be9

castling, autoformatting

view details

neerajensritharan

commit sha 2dac05c2d4ace83711b14ff739a80abd55eb12e9

gitignore

view details

neerajensritharan

commit sha 60d8a9fc621ba014772684c6dc9a7dd830a91a05

pawn promotions + tests

view details

push time in a month

PublicEvent
PublicEvent

push eventneery1218/OFCSolver

neery1218

commit sha 196968562e04bdc5b17afbbb0aef2f701ff26bdf

Update README.md

view details

push time in a month

push eventneery1218/chess

Janujan Sritharan

commit sha 54abdef079793ee7b6b906d3cd4ca53a0f7a7d88

Added knight, rook, bishop, queen get_valid_moves functions. Also added tests for them

view details

Janujan Sritharan

commit sha 2233b32a75e626a4e98287f282b39954ecacbed5

Followed DRY principle, made increment function for bishop, rook, and queen. Also added two tests for each.

view details

Janujan Sritharan

commit sha 4be7922a4d4ab525348fae2efd4f57d00e00f39d

Implemented pawn get_valid_moves with en passant working (will test more thoroughly later though)

view details

Janujan Sritharan

commit sha 3c52ebb449c9068617127263ad5dce929b2f2b5c

Format

view details

Janujan Sritharan

commit sha 0c20a3525553b62f32c7114097ea208cd726ddaf

Added piece_copy (gets deep copy of each piece)

view details

Janujan Sritharan

commit sha 2f30526d3317158bbcf0b03c3bc303b57c8a8698

Made board deep copy function

view details

Janujan Sritharan

commit sha 1b9493bcd57a6ac4434b626de641cd6a929e5f37

Split long assert statements into multiple

view details

Janujan Sritharan

commit sha 8dd7d42f98223bfe873b7bd7bbe34fdb3b67bc61

Copying methods changedd to deepcopy

view details

neery1218

commit sha ea759003c803b66bb48626d5fb8aef9bb74261a4

Merge pull request #2 from janujan99/main All pieces other than king have full functionality, test included

view details

push time in a month

Pull request review commentneery1218/chess

All pieces other than king have full functionality, test included

+from board_and_pieces import Pawn+from board_and_pieces import Knight+from board_and_pieces import Bishop+from board_and_pieces import Rook+from board_and_pieces import Queen+from board_and_pieces import King from board_and_pieces import Board+from board_and_pieces import Colour import pytest ++def read_board(board_file: str):+    f = open("./testing_boards/"+board_file)++    lines = f.read().split("\n")++    board_dict = {}+    for y in range(len(lines)):+        squares = lines[y].split()+        for x in range(len(squares)):+            if squares[x] == "K":+                board_dict[(x, y)] = King(x, y, Colour.WHITE)+            elif squares[x] == "k":+                board_dict[(x, y)] = King(x, y, Colour.BLACK)+            elif squares[x] == "Q":+                board_dict[(x, y)] = Queen(x, y, Colour.WHITE)+            elif squares[x] == "q":+                board_dict[(x, y)] = Queen(x, y, Colour.BLACK)+            elif squares[x] == "R":+                board_dict[(x, y)] = Rook(x, y, Colour.WHITE)+            elif squares[x] == "r":+                board_dict[(x, y)] = Rook(x, y, Colour.BLACK)+            elif squares[x] == "B":+                board_dict[(x, y)] = Bishop(x, y, Colour.WHITE)+            elif squares[x] == "b":+                board_dict[(x, y)] = Bishop(x, y, Colour.BLACK)+            elif squares[x] == "N":+                board_dict[(x, y)] = Knight(x, y, Colour.WHITE)+            elif squares[x] == "n":+                board_dict[(x, y)] = Knight(x, y, Colour.BLACK)+            elif squares[x] == "P":+                board_dict[(x, y)] = Pawn(x, y, Colour.WHITE)+            elif squares[x] == "p":+                board_dict[(x, y)] = Pawn(x, y, Colour.BLACK)+    return Board(board_dict)++ def test_board():     b = Board()     print(b)     knight_exists = False     for piece in b.board_dict:-        if b.board_dict[piece].letter == "K":+        if b.board_dict[piece].letter == "♞":             knight_exists = True-    +     assert knight_exists+++def test_knight():+    # use board1+    b = read_board("board1.txt")+    moves = b.board_dict[(1, 7)].get_valid_moves(b, "", (0, 0), (0, 0))++    b4 = read_board("board4.txt")+    assert set(moves) == set([(2, 5), (0, 5)])+++def test_bishop():+    # use board1+    b = read_board("board1.txt")+    moves = b.board_dict[(2, 7)].get_valid_moves(b, "", (0, 0), (0, 0))+    assert set(moves) == set([])++    # use board 4+    b4 = read_board("board4.txt")+    moves4 = b4.board_dict[(6, 3)].get_valid_moves(b4, "", (0, 0), (0, 0))++    assert set(moves4) == set([(5, 2), (7, 2), (7, 4), (5, 4), (4, 5)])+++def test_rook():+    # use board1+    b = read_board("board1.txt")+    moves = b.board_dict[(0, 0)].get_valid_moves(b, "", (0, 0), (0, 0))+    assert set(moves) == set([])++    # using board4+    b4 = read_board("board4.txt")+    moves4 = b4.board_dict[(4, 7)].get_valid_moves(b4, "", (0, 0), (0, 0))+    assert set(moves4) == set([(4, 6), (4, 5), (4, 4), (4, 3)])+++def test_queen():+    # use board1+    b = read_board("board1.txt")+    moves = b.board_dict[(3, 0)].get_valid_moves(b, "", (0, 0), (0, 0))+    assert set(moves) == set([])++    # using board4+    b4 = read_board("board4.txt")+    moves4 = b4.board_dict[(2, 1)].get_valid_moves(b4, "", (0, 0), (0, 0))+    assert set(moves4) == set([(1, 0), (3, 0), (2, 2), (3, 2)])+++def test_pawn():+    # use board1+    b = read_board("board1.txt")+    moves = b.board_dict[(0, 6)].get_valid_moves(b, "", (0, 0), (0, 0))+    assert set(moves) == set([(0, 5), (0, 4)])+    # test pawn capture (non en-passant)+    b5 = read_board("board5.txt")+    b5.board_dict[(3, 3)].has_moved = True+    b5.board_dict[(4, 4)].has_moved = True+    moves5 = b5.board_dict[(3, 3)].get_valid_moves(b5, "", (0, 0), (0, 0))+    assert set(moves5) == set([(4, 4), (3, 4)])+    # test pawn capture (en-passant)+    b6 = read_board("board6.txt")+    last_moved = "♙"+    initial_pos = (1, 1)+    final_pos = (1, 3)+    b6.board_dict[(0, 3)].has_moved = True+    moves6 = b6.board_dict[(0, 3)].get_valid_moves(+        b6, last_moved, initial_pos, final_pos)+    assert set(moves6) == set([(0, 2), (1, 2, "en passant")])+++def test_piece_copy():+    p = Pawn(1, 1, Colour.WHITE)+    d = p.piece_copy()++    assert p.x == d.x and p.y == d.y and p.colour == d.colour and p.has_moved == d.has_moved and p.letter == d.letter and not p is d

in general, you want to split up an assert like this into multiple asserts. If you have a single assert statement like this, and if fails, there's no way to figure out which statement within the assert failed.

janujan99

comment created time in a month

Pull request review commentneery1218/chess

All pieces other than king have full functionality, test included

 def __str__(self) -> None:                     arr.append("-")             s += " ".join(arr) + "\n"         return s- \ No newline at end of file++    def board_copy(self):

Insteads of piece_copy(), and board_copy(), why don't you implement the deepcopy special method for all pieces and the Board? That way, you can just do

b = Board() b_copy = b.deepcopy()

see https://docs.python.org/3/library/copy.html

In order for a class to define its own copy implementation, it can define special methods copy() and deepcopy().

janujan99

comment created time in a month

PullRequestReviewEvent
PullRequestReviewEvent

push eventneery1218/chess

neery1218

commit sha f870bc27064762edacdaab12793f8912cc706744

Create pylint.yml

view details

push time in a month

PullRequestReviewEvent

Pull request review commentneery1218/chess

All pieces other than king have full functionality, test included

 from enum import Enum + class Colour(Enum):     WHITE = 1     BLACK = 2 + class Piece:-    def __init__(self, x: int, y: int, colour: Enum) -> None:+    def __init__(self, x: int, y: int, colour: Enum, has_moved=False) -> None:         self.x = x         self.y = y         self.colour = colour         self.has_moved = False -    def on_board(self, x: int, y: int) -> bool:-        return 0 <= x < 8 and 0 <= y < 8+    def on_board(self, pos: tuple) -> bool:+        return 0 <= pos[0] < 8 and 0 <= pos[1] < 8++    def increment(self, increment_lst, board):+        possible_moves = []+        x = self.x+        y = self.y+        for x_inc, y_inc in increment_lst:+            for i in range(8):+                print((x+x_inc*(i+1), y+y_inc*(i+1)))+                if not self.on_board((x+x_inc*(i+1), y+y_inc*(i+1))):+                    break+                elif (x+x_inc*(i+1), y+y_inc*(i+1)) in board.board_dict:+                    if board.board_dict[(x+x_inc*(i+1), y+y_inc*(i+1))].colour != self.colour:+                        possible_moves.append((x+x_inc*(i+1), y+y_inc*(i+1)))+                    break+                else:+                    possible_moves.append((x+x_inc*(i+1), y+y_inc*(i+1)))+        return possible_moves+  class Knight(Piece):-    def __init__(self, x: int, y: int, colour: Enum):+    def __init__(self, x: int, y: int, colour: Enum, has_moved=False):         super().__init__(x, y, colour)-        self.letter = "N" if colour == Colour.WHITE else "n"+        self.letter = "♘" if colour == Colour.BLACK else "♞"++    def get_valid_moves(self, board, last_moved: str, initial_pos: str, final_pos: str):+        x = self.x+        y = self.y+        all_squares = [(x+1, y-2), (x+2, y-1), (x+2, y+1), (x+1, y+2),+                       (x-1, y-2), (x-2, y-1), (x-1, y+2), (x-2, y+1)]+        # filter out moves that are not even on the board+        moves_on_board = [+            square for square in all_squares if self.on_board(square)]++        valid_moves = [move for move in moves_on_board if (+            not move in board.board_dict) or (board.board_dict[move].colour != self.colour)]++        return valid_moves   class Bishop(Piece):-    def __init__(self, x: int, y: int, colour: Enum):+    def __init__(self, x: int, y: int, colour: Enum, has_moved=False):         super().__init__(x, y, colour)-        self.letter = "B" if colour == Colour.WHITE else "b"+        self.letter = "♗" if colour == Colour.BLACK else "♝"++    def get_valid_moves(self, board, last_moved: str, initial_pos: str, final_pos: str):+        return self.increment([(1, -1), (1, 1), (-1, 1), (-1, -1)], board)   class Rook(Piece):-    def __init__(self, x: int, y: int, colour: Enum):+    def __init__(self, x: int, y: int, colour: Enum, has_moved=False):         super().__init__(x, y, colour)-        self.letter = "R" if colour == Colour.WHITE else "r"+        self.letter = "♖" if colour == Colour.BLACK else "♜"++    def get_valid_moves(self, board, last_moved: str, initial_pos: str, final_pos: str):+        return self.increment([(1, 0), (0, 1), (-1, 0), (0, -1)], board)   class Queen(Piece):-    def __init__(self, x: int, y: int, colour: Enum):+    def __init__(self, x: int, y: int, colour: Enum, has_moved=False):         super().__init__(x, y, colour)-        self.letter = "Q" if colour == Colour.WHITE else "q"+        self.letter = "♕" if colour == Colour.BLACK else "♛"++    def get_valid_moves(self, board, last_moved: str, initial_pos: str, final_pos: str):+        return self.increment([(1, 0), (0, 1), (-1, 0), (0, -1), (1, -1), (1, 1), (-1, 1), (-1, -1)], board)   class King(Piece):-    def __init__(self, x: int, y: int, colour: Enum):+    def __init__(self, x: int, y: int, colour: Enum, has_moved=False):         super().__init__(x, y, colour)-        self.letter = "K" if colour == Colour.WHITE else "k"+        self.letter = "♔" if colour == Colour.BLACK else "♚"++    def get_valid_moves(self, board, last_moved: str, initial_pos: str, final_pos: str):+        x = self.x+        y = self.y   class Pawn(Piece):-    def __init__(self, x: int, y: int, colour: Enum):+    def __init__(self, x: int, y: int, colour: Enum, has_moved=False):         super().__init__(x, y, colour)-        self.letter = "P" if colour == Colour.WHITE else "p"+        self.letter = "♙" if colour == Colour.BLACK else "♟︎"+        self.direction_factor = 1 if colour == Colour.BLACK else -1++    def get_valid_moves(self, board, last_moved: str, initial_pos: str, final_pos: str):

should initial_pos, final_pos be array types?

janujan99

comment created time in a month