Skip to content

Commit 0a16802

Browse files
authored
Saint Alessia deck enabled (#2)
* Saint Alessia deck enabled * Fix naming, change version * Fix it in another PR
1 parent ae9d8a1 commit 0a16802

File tree

12 files changed

+61
-73
lines changed

12 files changed

+61
-73
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,6 @@ venv.bak/
105105

106106
# IDE-specific files
107107
.vscode/
108-
.idea/
108+
.idea/
109+
110+
examples/logs

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pip install scripts-of-tribute
2727

2828
## Getting Started
2929
### Creating your bot
30-
To create your own bot, you need to inherit from the `ScriptsOfTribute.base_ai.BaseAI` class and implement the required methods:
30+
To create your own bot, you need to inherit from the `scripts_of_tribute.base_ai.BaseAI` class and implement the required methods:
3131
```python
3232
def pregame_prepare(self):
3333
"""Optional: Prepare your bot before the game starts."""
@@ -49,7 +49,7 @@ def game_end(self, final_state):
4949
What's important here in the `play` method that bot should return `BasicMove` object from the list, it is because `Move` objects come from the engine with an Identification number `move_id` which is used to quickly identify whether move is legal or not.
5050

5151
### Running the game
52-
The `ScriptsOfTribute.game.Game` class is used to register and run your bots. Here's how to use it:
52+
The `scripts_of_tribute.game.Game` class is used to register and run your bots. Here's how to use it:
5353
```python
5454
from ScriptsOfTribute.game import Game
5555
from Bots.RandomBot import RandomBot
@@ -136,11 +136,11 @@ This code is available in the `examples` directory, as well with the example bot
136136

137137
## Contributing
138138
if you would like to work with the code locally you might need to (re)generate `protobuf` files.
139-
The library uses gRPC for communication with the C# .NET engine. The `.proto` files are located in the `ScriptsOfTribute/Protos` folder. To generate the necessary Python files, run:
139+
The library uses gRPC for communication with the C# .NET engine. The `.proto` files are located in the `scripts_of_tribute/protos` folder. To generate the necessary Python files, run:
140140
```bash
141-
python -m grpc_tools.protoc -IProtos --python_out=./Protos/ --grpc_python_out=Protos/. Protos/enums.proto Protos/basics.proto Protos/main.proto
141+
python -m grpc_tools.protoc -Iprotos --python_out=./protos/ --grpc_python_out=protos/. protos/enums.proto protos/basics.proto protos/main.proto
142142
```
143-
This will generate the required gRPC Python files in the `Protos` folder.
143+
This will generate the required gRPC Python files in the `protos` folder.
144144

145145
## License
146146
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

examples/Bots/MaxPrestigeBot.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import random
2+
import os
23

34
from scripts_of_tribute.base_ai import BaseAI
5+
from scripts_of_tribute.board import EndGameState, GameState
46
from scripts_of_tribute.enums import PlayerEnum, MoveEnum
57

68
class MaxPrestigeBot(BaseAI):
@@ -16,12 +18,14 @@ def select_patron(self, available_patrons):
1618

1719
def play(self, game_state, possible_moves, remaining_time):
1820
best_move = None
19-
best_move_val = -1
21+
best_move_val = -99
2022
if self.start_of_game:
2123
self.player_id = game_state.current_player.player_id
2224
self.start_of_game = False
2325

2426
for first_move in possible_moves:
27+
if first_move.command == MoveEnum.END_TURN:
28+
continue
2529
new_game_state, new_moves = game_state.apply_move(first_move)
2630

2731
if new_game_state.end_game_state is not None: # check if game is over, if we win we are fine with this move
@@ -40,7 +44,7 @@ def play(self, game_state, possible_moves, remaining_time):
4044
final_game_state, _ = new_game_state.apply_move(second_move)
4145
if final_game_state.end_game_state is not None:
4246
if final_game_state.end_game_state.winner == self.player_id:
43-
return second_move
47+
return first_move
4448
curr_val = final_game_state.current_player.prestige + final_game_state.current_player.power
4549
if curr_val > best_move_val:
4650
best_move = first_move
@@ -49,5 +53,26 @@ def play(self, game_state, possible_moves, remaining_time):
4953
return next(move for move in possible_moves if move.command == MoveEnum.END_TURN)
5054
return best_move
5155

52-
def game_end(self, final_state):
53-
pass
56+
def game_end(self, end_game_state: EndGameState, final_state: GameState):
57+
# Example how you can log your game for further analysis
58+
log_dir = "logs"
59+
os.makedirs(log_dir, exist_ok=True)
60+
61+
filename = f"game_log_{final_state.state_id}_{end_game_state.winner}.log"
62+
filepath = os.path.join(log_dir, filename)
63+
64+
try:
65+
with open(filepath, "w", encoding="utf-8") as f:
66+
f.write(f"=== Game Ended ===\n")
67+
f.write(f"Winner: {end_game_state.winner}\n")
68+
f.write(f"Reason: {end_game_state.reason}\n")
69+
f.write(f"Context: {end_game_state.AdditionalContext}\n\n")
70+
f.write("=== Completed Actions ===\n")
71+
72+
for action in final_state.completed_actions:
73+
f.write(action + "\n")
74+
75+
print(f"[INFO] Game log saved to: {filepath}")
76+
77+
except Exception as e:
78+
print(f"[ERROR] Failed to save game log: {e}")

examples/Bots/RandomBot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ def play(self, game_state, possible_moves, remaining_time):
1111
pick = random.choice(possible_moves)
1212
return pick
1313

14-
def game_end(self, final_state):
14+
def game_end(self, end_game_state, final_state):
1515
pass

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "scripts-of-tribute"
7-
version = "1.0.2"
7+
version = "1.0.3"
88
authors = [
99
{ name="Ematerasu", email="[email protected]" },
1010
]

scripts_of_tribute/base_ai.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import List
22

3-
from scripts_of_tribute.board import GameState
3+
from scripts_of_tribute.board import GameState, EndGameState
44
from scripts_of_tribute.enums import PatronId
55
from scripts_of_tribute.move import BasicMove
66

@@ -17,5 +17,5 @@ def select_patron(self, available_patrons: List[PatronId]):
1717
def play(self, game_state: GameState, possible_moves: List[BasicMove], remaining_time: int) -> BasicMove:
1818
raise NotImplementedError
1919

20-
def game_end(self, final_state):
20+
def game_end(self, end_game_state: EndGameState, final_state: GameState):
2121
pass

scripts_of_tribute/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class PatronId(Enum):
1010
PELIN = 6
1111
RED_EAGLE = 7
1212
TREASURY = 8
13+
SAINT_ALESSIA = 9
1314

1415
@classmethod
1516
def from_string(cls, patron_str: str) -> 'PatronId':

scripts_of_tribute/protos/enums.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enum PatronIdProto {
1212
PELIN = 6;
1313
RED_EAGLE = 7;
1414
TREASURY = 8;
15+
SAINT_ALESSIA = 9;
1516
}
1617

1718
enum MoveEnum

scripts_of_tribute/protos/enums_pb2.py

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts_of_tribute/protos/main_pb2.py

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)