Views
No views yet
| Range | Description |
|---|---|
| 0-63 | Player's hand cards (64 card slots) |
| 64-127 | Cards played this game |
| 128-191 | Current trick cards to beat |
| 192-255 | Opponent card estimates |
| 256-295 | Action mask (40 valid actions) |
| 296-327 | Context features (scores, positions, etc.) |
1from huggingface_hub import hf_hub_download
2import torch
3import sys
4
5# Download all necessary files
6for filename in ["modeling_gangoffour.py", "game_utils.py", "rules.py", "config.json", "model.safetensors"]:
7 hf_hub_download(repo_id="quintana42/gang-of-four-neural", filename=filename, local_dir="./model")
8
9sys.path.insert(0, "./model")
10from modeling_gangoffour import GangOfFourNet
11from game_utils import Card, GameEncoder, decode_action
12
13# Load model
14model = GangOfFourNet.from_pretrained("./model")
15model.eval()
16
17# Parse your hand from string notation
18hand = Card.parse_hand("1G 3R 5Y 7G 10R Dragon")
19print(f"Hand: {[str(c) for c in hand]}")
20
21# Define valid plays (in a real game, comes from game rules)
22valid_plays = [
23 [], # Pass
24 [hand[0]], # Play 1G
25 [hand[1]], # Play 3R
26 [hand[2]], # Play 5Y
27]
28
29# Encode the game state
30encoder = GameEncoder()
31state, ordered_plays = encoder.encode_simple(
32 hand=hand,
33 valid_plays=valid_plays,
34 is_leading=True, # We're leading (no trick to beat)
35)
36
37# Run inference
38state_tensor = torch.tensor(state).unsqueeze(0)
39mask_tensor = torch.tensor(state[256:296]).unsqueeze(0)
40
41with torch.no_grad():
42 logits, declare_prob = model(state_tensor, mask_tensor)
43
44# Decode the result
45action_idx = logits.argmax(dim=1).item()
46chosen_play = decode_action(action_idx, ordered_plays)
47
48if chosen_play is None:
49 print("Model chose: PASS")
50else:
51 print(f"Model chose: {[str(c) for c in chosen_play]}")
52print(f"Declare last card probability: {declare_prob.item():.3f}")1from game_utils import Card
2
3# Single cards
4card = Card.parse("5G") # 5 Green
5card = Card.parse("10R") # 10 Red
6card = Card.parse("1M") # Multi-colored 1
7card = Card.parse("Dragon") # Dragon
8card = Card.parse("PhoenixG") # Phoenix Green
9
10# Multiple cards
11hand = Card.parse_hand("1G 3R 5Y Dragon PhoenixY")| Index | Card |
|---|---|
| 0-1 | 1 Green (2 copies) |
| 2-3 | 1 Yellow (2 copies) |
| 4-5 | 1 Red (2 copies) |
| 6-7 | 2 Green (2 copies) |
| ... | ... |
| 58-59 | 10 Red (2 copies) |
| 60 | Multi-colored 1 |
| 61 | Phoenix Green |
| 62 | Phoenix Yellow |
| 63 | Dragon |
(rank - 1) * 6 + color_idx * 2 + copy
where color_idx: GREEN=0, YELLOW=1, RED=2ordered_plays list returned by the encoder maps action indices to actual plays.rules.py to generate valid plays according to game rules:1from game_utils import Card
2from rules import get_valid_plays, get_combination_type, can_beat
3
4# Your hand and the trick to beat
5hand = Card.parse_hand("4G 4Y 4R 4G 7R 7Y 10G")
6trick = Card.parse_hand("6G 6R") # Pair of 6s
7
8# Get all legal plays
9valid_plays = get_valid_plays(hand, trick_to_beat=trick)
10
11for play in valid_plays:
12 if play:
13 combo_type = get_combination_type(play)
14 print(f"{combo_type}: {[str(c) for c in play]}")
15 else:
16 print("PASS")
17# Output:
18# pair: ['7R', '7Y']
19# gang_of_four: ['4G', '4Y', '4R', '4G'] # Gang beats anything!
20# PASS
21
22# Check if a specific play beats a trick
23play = Card.parse_hand("8G 8Y")
24print(can_beat(play, trick)) # Truerules.py:get_valid_plays(hand, trick_to_beat) - Get all legal playsget_combination_type(cards) - Identify combination (single, pair, gang, etc.)can_beat(play, trick) - Check if play legally beats trickget_all_combinations(hand) - Get all possible combinations from hand1from modeling_gangoffour import GangOfFourNet
2
3# Load from Hugging Face Hub
4model = GangOfFourNet.from_pretrained("quintana42/gang-of-four-neural")
5
6# Or load from local directory
7model = GangOfFourNet.from_pretrained("./my_local_model")
8
9# Use GPU
10model = GangOfFourNet.from_pretrained("quintana42/gang-of-four-neural", device="cuda")1# After training
2model.save_pretrained("./my_trained_model")config.json - Model configurationmodel.safetensors - Model weights (safetensors format)modeling_gangoffour.py - Model code with from_pretrained supportgame_utils.py - Encoding/decoding utilities (Card, GameEncoder, decode_action)rules.py - Game rules (get_valid_plays, can_beat, get_combination_type)torch>=2.0.0
safetensors>=0.4.0
huggingface_hub>=0.20.01@misc{gangoffour-neural,
2 author = {quintana42},
3 title = {Gang of Four Neural AI},
4 year = {2026},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/quintana42/gang-of-four-neural}
7}