refuses to work, movement broken
This commit is contained in:
parent
7069c9df47
commit
1b9820b6c9
1 changed files with 9 additions and 36 deletions
45
player.py
45
player.py
|
@ -35,17 +35,15 @@ class Piece:
|
|||
validated_jumps = []
|
||||
|
||||
for jump in valid_jumps:
|
||||
if not self.hive_integrity_check(jump, board):
|
||||
if not self.hive_integrity_check(board):
|
||||
validated_jumps.append(jump)
|
||||
return validated_jumps
|
||||
|
||||
def hive_integrity_check(self, jump, board):
|
||||
def hive_integrity_check(self, board):
|
||||
board_copy = {p: {q: board[p][q] for q in board[p]} for p in board}
|
||||
|
||||
# Simulate the move
|
||||
# See if the hive falls apart without the piece (if so, then the move wasnt valid)
|
||||
board_copy[self.p][self.q] = None # Remove the piece from its current position
|
||||
new_p, new_q = jump
|
||||
board_copy[new_p][new_q] = self # Place the piece in the new position
|
||||
|
||||
# Get all remaining pieces on the board
|
||||
remaining_pieces = [
|
||||
|
@ -293,48 +291,23 @@ class Player(Base.Board):
|
|||
valid_placements.append((p, q))
|
||||
|
||||
return valid_placements
|
||||
valid_placements = []
|
||||
|
||||
# If the board is empty, place the piece at the center.
|
||||
if all(not row for row in translated_board.values()):
|
||||
return [(3, 6)]
|
||||
|
||||
# Iterate over each tile in the board
|
||||
for p, row in translated_board.items():
|
||||
for q, tile_content in row.items():
|
||||
# Check if the tile is empty
|
||||
if tile_content == "":
|
||||
# Check if any neighbors are your pieces and none are opponent's pieces
|
||||
neighbors = get_neighbors(p, q)
|
||||
if any(
|
||||
translated_board.get(np, {}).get(nq) and
|
||||
translated_board[np][nq].team == self.myIsUpper
|
||||
for np, nq in neighbors
|
||||
) and not any(
|
||||
translated_board.get(np, {}).get(nq) and
|
||||
translated_board[np][nq].team != self.myIsUpper
|
||||
for np, nq in neighbors
|
||||
):
|
||||
valid_placements.append((p, q))
|
||||
|
||||
return valid_placements
|
||||
|
||||
def move(self, iter = 0):
|
||||
def move(self):
|
||||
translated_board, total_pieces_count, _ = self.translate_board(self.board)
|
||||
|
||||
def choose_random_piece(pieces):
|
||||
return random.choice(pieces) if pieces else None
|
||||
|
||||
# Check if the queen bee is placed
|
||||
be_unplaced = "q" in [k.lower() for k in self.myPieces.keys()] and {k.lower(): v for k,v in self.myPieces.items()}["q"]!=0
|
||||
bee_unplaced = "q" in [k.lower() for k in self.myPieces.keys()] and {k.lower(): v for k,v in self.myPieces.items()}["q"]!=0
|
||||
|
||||
# Logic for placing the queen bee based on a coin flip or on the 4th turn
|
||||
if be_unplaced and (total_pieces_count > 3 or random.choice([True, False])):
|
||||
queen_bee = self.get_piece_class('Q')(None, None, self.myIsUpper)
|
||||
if bee_unplaced and (total_pieces_count > 3 or random.choice([True, False])):
|
||||
queen_bee = self.get_piece_class('Q')(None, None, True)
|
||||
valid_placements = self.get_valid_placements(translated_board, queen_bee)
|
||||
if valid_placements:
|
||||
new_p, new_q = random.choice(valid_placements)
|
||||
return queen_bee.get_piece_info(self.myIsUpper)[:1] + [None, None, new_p, new_q]
|
||||
return queen_bee.get_piece_info(self.myIsUpper)[0]+ [None, None, new_p, new_q]
|
||||
|
||||
if total_pieces_count == 0:
|
||||
piece_to_place = choose_random_piece(self.get_unplaced_pieces())
|
||||
|
@ -365,7 +338,7 @@ class Player(Base.Board):
|
|||
piece
|
||||
for row in translated_board.values()
|
||||
for piece in row.values()
|
||||
if piece and piece.validate_jumps(translated_board) and piece.team
|
||||
if piece and piece.team and piece.validate_jumps(translated_board)
|
||||
]
|
||||
chosen_piece = choose_random_piece(movable_pieces)
|
||||
if chosen_piece:
|
||||
|
|
Loading…
Add table
Reference in a new issue