uniconhq / unicon-backend

0 stars 1 forks source link

feat: add object access node #26

Closed seelengxd closed 1 month ago

seelengxd commented 1 month ago

new steps

  1. ObjectAccessNode - to extract field from dictionary
  2. OutputStep

fixes

modification to original utils.py in json file:

  1. generate_init_state is now a dictionary including the move
    def generate_init_state():
    state = [
        ["B"] * COL,
        ["B"] * COL,  # 2 black rows
        ["_"] * COL,
        ["_"] * COL,  # 2 empty rows
        ["W"] * COL,
        ["W"] * COL,  # 2 white rows
    ]
    return {"board": state, "move": "B"}
  2. adds this function

    # makes a move effective on the board by modifying board state, or returning a new board with updated board state
    def state_change_modified(state, move, in_place=True):
    curr_board = state["board"]
    
    from_, to_ = move
    """Updates the board configuration by modifying existing values if in_place is set to True, or creating a new board with updated values if in_place is set to False"""
    board = curr_board
    if not in_place:
        board = copy.deepcopy(curr_board)
    if is_valid_move(board, from_, to_):
        board[from_[0]][from_[1]] = "_"
        board[to_[0]][to_[1]] = "B"
    
    state["board"] = curr_board
    state["move"] = "W" if state["move"] == "B" else "B"