Skip to content

Commit

Permalink
Reduce attacking a lighthouse to let the bot move
Browse files Browse the repository at this point in the history
  • Loading branch information
onizucraft committed Nov 14, 2024
1 parent 09e87be commit 1608b48
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def new_turn_action(self, turn: game_pb2.NewTurn) -> game_pb2.NewAction:

# Si estamos en un faro...
if (cx, cy) in lighthouses:
# Conectar con faro remoto válido siempre que se pueda
# Conectar con faro remoto válido si podemos
if lighthouses[(cx, cy)].Owner == self.player_num:
possible_connections = []
for dest in lighthouses:
Expand Down Expand Up @@ -66,18 +66,19 @@ def new_turn_action(self, turn: game_pb2.NewTurn) -> game_pb2.NewAction:
self.countT += 1
return action

# Atacar el faro siempre que se pueda
energy = random.randrange(turn.Energy + 1)
action = game_pb2.NewAction(
Action=game_pb2.ATTACK,
Energy=energy,
Destination=game_pb2.Position(X=turn.Position.X, Y=turn.Position.Y),
)
bgt = BotGameTurn(turn, action)
self.turn_states.append(bgt)

self.countT += 1
return action
# 60% de posibilidades de atacar el faro
if random.randrange(100) < 60:
energy = random.randrange(turn.Energy + 1)
action = game_pb2.NewAction(
Action=game_pb2.ATTACK,
Energy=energy,
Destination=game_pb2.Position(X=turn.Position.X, Y=turn.Position.Y),
)
bgt = BotGameTurn(turn, action)
self.turn_states.append(bgt)

self.countT += 1
return action

# Mover aleatoriamente
moves = ((-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1))
Expand Down

0 comments on commit 1608b48

Please sign in to comment.