fix my code "keyCells, tempkeyCells = {}, {}

class Base:
    def printBoard(base: list) -> None:
        lastRow = [chr(i) for i in range(ord("a"),ord("h")+1)]
        for rowNum, row in enumerate(base):print(f"{8-rowNum}. {' '.join(row)}")
        print(f"   {'. '.join(lastRow)}.")

    def makeBoard() -> list:
        base, WHITE, BLACK, CENTER = [], [["wp","wp","wp","wp","wp","wp","wp","wp"],["wr","wn","wb","wq","wk","wb","wn","wr"]], [["br","bn","bb","bq","bk","bb","bn","br"],["bp","bp","bp","bp","bp","bp","bp","bp"]], [["--" for i in range(8)] for j in range(4)]
        base.extend(BLACK); base.extend(CENTER); base.extend(WHITE)
        Base.printBoard(base)
        for row in range(8):
            for col in range(8):chessCoor = f"{chr(col+ord('a'))}{8-row}";keyCells[chessCoor] = base[row][col]
        return base

    def modifyKeyCells(initial: str, piece: str, initialMove:str, finalMove: str, available: list, check: bool) -> bool:
        if finalMove in available:
            if not check:tempkeyCells[finalMove] = f"{initial}{piece}";tempkeyCells[initialMove] = "--"
            return True
        return False

    def modifyBoard() -> list:
        base, temp, count = [], [], 0
        for ele in list(keyCells.items()):
            temp.append(ele[1])
            count += 1
            if count % 8 == 0:base.append(temp);temp = []
        return base

    def outroPerMove() -> None:
        for i, j in tempkeyCells.items():keyCells[i] = j
        base = Base.modifyBoard();Base.printBoard(base)

class Algorithms:
    def vertical(initial: str, initialMove: str, finalMove: str) -> list:
        if initialMove[0] == initialMove[0]:
            available, temp = [], []
            for i in list(keyCells.keys()):
                if i[0] == initialMove[0]:temp.append(i)
            if temp != []:
                previous = initialMove
                indexCell1 = temp[::-1].index(initialMove)
                for i in temp[::-1][indexCell1+1:]:
                    if keyCells[i] != "--" and keyCells[i][0] == keyCells[previous][0]:break
                    elif keyCells[i][0] != initial:available.append(i)
                    previous = i
                previous = initialMove;indexCell2 = temp.index(initialMove)
                for i in temp[indexCell2+1:]:
                    if keyCells[i] != "--" and keyCells[i][0] == keyCells[previous][0]:break
                    elif keyCells[i][0] != initial:available.append(i)
                    previous = i
                return available
        return []

    def horizontal(initial: str, initialMove: str, finalMove: str) -> list:
        if initialMove[1] == initialMove[1]:
            available, temp = [], []
            for i in list(keyCells.keys()):
                if i[1] == initialMove[1]:temp.append(i)
            if temp != []:
                previous = initialMove
                indexCell1 = temp.index(initialMove)
                for i in temp[indexCell1+1:]:
                    if keyCells[i] != "--" and keyCells[i][0] == keyCells[previous][0]:break
                    elif keyCells[i][0] != initial:available.append(i)
                    previous = i
                previous = initialMove;indexCell2 = temp[::-1].index(initialMove)
                for i in temp[indexCell2+1:]:
                    if keyCells[i] != "--" and keyCells[i][0] == keyCells[previous][0]:break
                    elif keyCells[i][0] != initial:available.append(i)
                    previous = i
                return available
        return []

    def diagonalLR(initial: str, initialMove: str) -> list:
        available, temp = [], []
        for i in list(keyCells.keys()):
            if ord(i[0])-ord(initialMove[0]) == int(initialMove[1])-int(i[1]) or i == initialMove:temp.append(i)
        if temp != []:
            previous = initialMove
            indexCell1 = temp.index(initialMove)
            for i in temp[indexCell1+1:]:
                if keyCells[i] != "--" and keyCells[i][0] == keyCells[previous][0]:break
                elif keyCells[i][0] != initial:available.append(i)
                previous = i
            previous = initialMove;indexCell2 = temp[::-1].index(initialMove)
            for i in temp[::-1][indexCell2+1:]:
                if keyCells[i] != "--" and keyCells[i][0] == keyCells[previous][0]:break
                elif keyCells[i][0] != initial:available.append(i)
                previous = i
            return available
        return []

    def diagonalRL(initial: str, initialMove: str) -> list:
        available, temp = [], []
        for i in list(keyCells.keys()):
            if ord(i[0])-ord(initialMove[0]) == int(i[1])-int(initialMove[1]) or i == initialMove:temp.append(i)
        if temp != []:
            previous = initialMove
            indexCell1 = temp.index(initialMove)
            for i in temp[indexCell1+1:]:
                if keyCells[i] != "--" and keyCells[i][0] == keyCells[previous][0]:break
                elif keyCells[i][0] != initial:available.append(i)
                previous = i
            previous = initialMove;indexCell2 = temp[::-1].index(initialMove)
            for i in temp[::-1][indexCell2+1:]:
                if keyCells[i] != "--" and keyCells[i][0] == keyCells[previous][0]:break
                elif keyCells[i][0] != initial:available.append(i)
                previous = i
            return available
        return []

    def checks(initial: str, coor: str) -> bool:
        kingCoor, initials = "", ["w","b"];initials.remove(initial)
        if coor == "":
            for i, j in tempkeyCells.items():
                if j == f"{initial}k":kingCoor = i
        else:kingCoor = coor
        for i, j in tempkeyCells.items():
            if j[1] == "p":
                valid = Pieces.pawn(initials[0], i, kingCoor, True)
                if valid:return True
            elif j[1] == "n":
                valid = Pieces.horse(initials[0], i, kingCoor, True)
                if valid:return True
            elif j[1] == "r":
                valid = Pieces.rook(initials[0], i, kingCoor, True)
                if valid:return True
            elif j[1] == "b":
                valid = Pieces.bishop(initials[0], i, kingCoor, True)
                if valid:return True
            elif j[1] == "q":
                valid = Pieces.queen(initials[0], i, kingCoor, True)
                if valid:return True
        return False

    def checkmate(initial: str) -> bool:
        available, kingCoor, initials, surrounds, result = [], "", ["w","b"], [(-1,-1),(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1)], [];initials.remove(initial)
        for i, j in tempkeyCells.items():
            if j == f"{initials[0]}k":kingCoor = i
        for surround in surrounds:
            checkCoor = (ord(kingCoor[0])+surround[0]-ord("a"), int(kingCoor[1])+surround[1])
            if checkCoor[0] in range(8) and checkCoor[1] in range(1,9):
                checkChessCoor = chr(checkCoor[0]+97)+str(checkCoor[1]);piece = keyCells[checkChessCoor]
                if piece == "--" or piece[0] == initial:available.append(checkChessCoor)
        available.append(kingCoor)
        for temp in available:result.append((Algorithms.checks(initials[0], temp),temp))
        for temp in result:
            if temp[0]:available.remove(temp[1])
        if available == []:return True, available
        return False, available

    def pin(initial: str, position: str) -> bool:
        test, initials, kingCoor = {}, ["w","b"], "";initials.remove(initial)
        for i, j in tempkeyCells.items():test[i] = j
        test[position] = "--"
        for i, j in tempkeyCells.items():
            if j == f"{initials[0]}k":kingCoor = i
        for i, j in test.items():
            if j[0] == initials[0]:
                if j[1] == "p":
                    valid = Pieces.pawn(initials[0], i, kingCoor, True)
                    if valid:return True
                elif j[1] == "n":
                    valid = Pieces.horse(initials[0], i, kingCoor, True)
                    if valid:return True
                elif j[1] == "r":
                    valid = Pieces.rook(initials[0], i, kingCoor, True)
                    if valid:return True
                elif j[1] == "b":
                    valid = Pieces.bishop(initials[0], i, kingCoor, True)
                    if valid:return True
                elif j[1] == "q":
                    valid = Pieces.queen(initials[0], i, kingCoor, True)
                    if valid:return True
        return False

class Pieces:
    def pawn(initial: str, initialMove: str, finalMove: str, check: bool) -> bool:
        available, initials = [], ["w","b"];initials.remove(initial)
        if initial == "w" and initialMove[1] == "2":surrounds = [(-1,1),(0,1),(1,1),(0,2)]
        elif initial == "b" and initialMove[1] == "7":surrounds = [(0,-1),(0,-2),(1,-1),(-1,1)]
        elif initial == "w":surrounds = [(-1,1),(0,1),(1,1)]
        else:surrounds = [(-1,-1),(0,-1),(1,-1)]
        for surround in surrounds:
            checkCoor = (ord(initialMove[0])+surround[0]-ord("a"), int(initialMove[1])+surround[1])
            if checkCoor[0] in range(8) and checkCoor[1] in range(1,9):
                checkChessCoor = chr(checkCoor[0]+97)+str(checkCoor[1]);piece = keyCells[checkChessCoor]
                if piece == "--" and checkChessCoor[0] == initialMove[0] or piece[0] in initials:available.append(checkChessCoor)
        result = Base.modifyKeyCells(initial, "p", initialMove, finalMove, available, check);return result

    def horse(initial: str, initialMove: str, finalMove: str, check: bool) -> bool:
        available, initials = [], ["w","b"];initials.remove(initial)
        surrounds = [(2,1),(2,-1),(-1,2),(1,2),(-2,1),(-2,-1),(-1,-2),(1,-2)]
        for surround in surrounds:
            checkCoor = (ord(initialMove[0])-ord("a")+surround[0], int(initialMove[1])+surround[1])
            if checkCoor[0] in range(8) and checkCoor[1] in range(1,9):
                checkChessCoor = chr(checkCoor[0]+97)+str(checkCoor[1])
                piece = keyCells[checkChessCoor]
                if piece == "--" or piece[0] in initials:available.append(checkChessCoor)
        result = Base.modifyKeyCells(initial, "n", initialMove, finalMove, available, check);return result

    def rook(initial: str, initialMove: str, finalMove: str, check: bool) -> bool:
        available = [];available.extend(Algorithms.vertical(initial, initialMove, finalMove));available.extend(Algorithms.horizontal(initial, initialMove, finalMove));result = Base.modifyKeyCells(initial, "r", initialMove, finalMove, available, check);return result

    def bishop(initial: str, initialMove: str, finalMove: str, check: bool) -> bool:
        available = [];available.extend(Algorithms.diagonalLR(initial, initialMove));available.extend(Algorithms.diagonalRL(initial, initialMove));result = Base.modifyKeyCells(initial, "b", initialMove, finalMove, available, check);return result
    
    def queen(initial: str, initialMove: str, finalMove: str, check: bool) -> bool:
        available = [];available.extend(Algorithms.diagonalLR(initial, initialMove));available.extend(Algorithms.diagonalRL(initial, initialMove));available.extend(Algorithms.vertical(initial, initialMove, finalMove));available.extend(Algorithms.horizontal(initial, initialMove, finalMove));result = Base.modifyKeyCells(initial, "q", initialMove, finalMove, available, check);return result

    def king(initial: str, initialMove: str, finalMove: str, check: bool) -> bool:
        available, initials = [], ["w","b"];initials.remove(initial)
        surrounds = [(-1,-1),(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1)]
        for surround in surrounds:
            checkCoor = (ord(initialMove[0])+surround[0]-ord("a"), int(initialMove[1])+surround[1])
            if checkCoor[0] in range(8) and checkCoor[1] in range(1,9):
                checkChessCoor = chr(checkCoor[0]+97)+str(checkCoor[1]);piece = keyCells[checkChessCoor]
                if piece == "--" and checkChessCoor[0] == initialMove[0] or piece[0] in initials:available.append(checkChessCoor)
        result = Base.modifyKeyCells(initial, "k", initialMove, finalMove, available, check);return result

def game(moves: list) -> None:
    global tempkeyCells, keyCells;previous, pieceMove, blackWin, whiteWin = None, False, False, False
    for num, move in enumerate(moves):
        if move[0][0] == "w":player = "white move: "
        elif move[0][0] == "b":player = "black move: "
        print(player+f"{move[0]}({move[1][0][0]}.{move[1][0][1]}.,{move[1][1][0]}.{move[1][1][1]}.)")
        if move[0][0] == previous:print(f"error {move[0]}({move[1][0][0]}.{move[1][0][1]}.,{move[1][1][0]}.{move[1][1][1]}.)");break
        initialMove, finalMove, tempkeyCells, valid = move[1][0], move[1][1], {}, False
        for i, j in keyCells.items():tempkeyCells[i] = j
        if move[0][1] == "p":
            if tempkeyCells[initialMove][1] == "p":
                resultTemp = Algorithms.pin(move[0][0], initialMove)
                if not resultTemp:valid = Pieces.pawn(move[0][0], initialMove, finalMove, False)
            pieceMove = True
        elif move[0][1] == "n":
            if tempkeyCells[initialMove][1] == "n":
                resultTemp = Algorithms.pin(move[0][0], initialMove)
                if not resultTemp:valid = Pieces.horse(move[0][0], initialMove, finalMove, False)
            pieceMove = True
        elif move[0][1] == "r":
            if tempkeyCells[initialMove][1] == "r":
                resultTemp = Algorithms.pin(move[0][0], initialMove)
                if not resultTemp:valid = Pieces.rook(move[0][0], initialMove, finalMove, False)
            pieceMove = True
        elif move[0][1] == "b":
            if tempkeyCells[initialMove][1] == "b":
                resultTemp = Algorithms.pin(move[0][0], initialMove)
                if not resultTemp:valid = Pieces.bishop(move[0][0], initialMove, finalMove, False)
            pieceMove = True
        elif move[0][1] == "q":
            if tempkeyCells[initialMove][1] == "q":
                resultTemp = Algorithms.pin(move[0][0], initialMove)
                if not resultTemp:valid = Pieces.queen(move[0][0], initialMove, finalMove, False)
            pieceMove = True
        elif move[0][1] == "k":
            if tempkeyCells[initialMove][1] == "k":valid = Pieces.king(move[0][0], initialMove, finalMove, False)
            pieceMove = True
        if pieceMove and valid:
            valid = Algorithms.checks(move[0][0], "")
            if valid:
                result, available = Algorithms.checkmate(move[0][0])
                if result:
                    if move[0][0] == "w":whiteWin = True
                    elif move[0][0] == "b":blackWin = True
                    if num == len(moves)-1:
                        Base.outroPerMove()
                        if move[0][0] == "w":print("white win!")
                        elif move[0][0] == "b":print("black win!")
                        break
                elif not result and (whiteWin or blackWin):
                    if move[0][0] == "w":whiteWin = False
                    elif move[0][0] == "b":blackWin = False
                elif result and (whiteWin or blackWin):
                    Base.outroPerMove()
                    if move[0][0] == "w":print("white win!")
                    elif move[0][0] == "b":print("black win!")
                    break
        if pieceMove and not valid:
            if not valid:
                print(f"error {move[0]}({move[1][0][0]}.{move[1][0][1]}.,{move[1][1][0]}.{move[1][1][1]}.)")
                for i, j in keyCells.items():tempkeyCells[i] = j
                break
        if pieceMove and valid:Base.outroPerMove()
        previous = move[0][0]

if __name__ == "__main__":
    rawMoves, moves = input().replace(".","").split(), []
    for move in rawMoves:temp = (move[:2], move[2:].strip("()").split(","));moves.append(temp)
    base = Base.makeBoard();game(moves)
" such that when i input "wp(e.2.,e.4.) bp(a.7.,a.6.) wp(d.2.,d.4.) bp(g.7.,g.5.) wq(d.1.,h.5.) bp(f.7.,f.6.)" it output "8. br bn bb bq bk bb bn br
7. bp bp bp bp bp bp bp bp
6. -- -- -- -- -- -- -- --
5. -- -- -- -- -- -- -- --
4. -- -- -- -- -- -- -- --
3. -- -- -- -- -- -- -- --
2. wp wp wp wp wp wp wp wp
1. wr wn wb wq wk wb wn wr
   a. b. c. d. e. f. g. h.
white move: wp(e.2.,e.4.)
8. br bn bb bq bk bb bn br
7. bp bp bp bp bp bp bp bp
6. -- -- -- -- -- -- -- --
5. -- -- -- -- -- -- -- --
4. -- -- -- -- wp -- -- --
3. -- -- -- -- -- -- -- --
2. wp wp wp wp -- wp wp wp
1. wr wn wb wq wk wb wn wr
   a. b. c. d. e. f. g. h.
black move: bp(a.7.,a.6.)
8. br bn bb bq bk bb bn br
7. -- bp bp bp bp bp bp bp
6. bp -- -- -- -- -- -- --
5. -- -- -- -- -- -- -- --
4. -- -- -- -- wp -- -- --
3. -- -- -- -- -- -- -- --
2. wp wp wp wp -- wp wp wp
1. wr wn wb wq wk wb wn wr
   a. b. c. d. e. f. g. h.
white move: wp(d.2.,d.4.)
8. br bn bb bq bk bb bn br
7. -- bp bp bp bp bp bp bp
6. bp -- -- -- -- -- -- --
5. -- -- -- -- -- -- -- --
4. -- -- -- wp wp -- -- --
3. -- -- -- -- -- -- -- --
2. wp wp wp -- -- wp wp wp
1. wr wn wb wq wk wb wn wr
   a. b. c. d. e. f. g. h.
black move: bp(g.7.,g.5.)
8. br bn bb bq bk bb bn br
7. -- bp bp bp bp bp -- bp
6. bp -- -- -- -- -- -- --
5. -- -- -- -- -- -- bp --
4. -- -- -- wp wp -- -- --
3. -- -- -- -- -- -- -- --
2. wp wp wp -- -- wp wp wp
1. wr wn wb wq wk wb wn wr
   a. b. c. d. e. f. g. h.
white move: wq(d.1.,h.5.)
8. br bn bb bq bk bb bn br
7. -- bp bp bp bp bp -- bp
6. bp -- -- -- -- -- -- --
5. -- -- -- -- -- -- bp wq
4. -- -- -- wp wp -- -- --
3. -- -- -- -- -- -- -- --
2. wp wp wp -- -- wp wp wp
1. wr wn wb -- wk wb wn wr
   a. b. c. d. e. f. g. h.
black move: bp(f.7.,f.6.)
error bp(f.7.,f.6.)"