Skip to content

Commit

Permalink
Add arcade rules
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Sep 8, 2024
1 parent 7dd86cd commit bd746f6
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 8 deletions.
35 changes: 31 additions & 4 deletions truncate_client/src/regions/arcade_pvp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,44 @@ impl ArcadeState {
9,
9,
seed.clone().map(|s| s.seed as u64),
GameRules::generation(rules_generation),
GameRules::arcade(),
);
game.add_player("P1".into());
game.add_player("P2".into());

match &game.rules.board_genesis {
truncate_core::rules::BoardGenesis::Passthrough => {
game.board = board.clone();
game.board.cache_special_squares();
}
truncate_core::rules::BoardGenesis::SpecificBoard(_) => unimplemented!(),
truncate_core::rules::BoardGenesis::Classic(_, _) => unimplemented!(),
truncate_core::rules::BoardGenesis::Random(params) => {
let rand_board = truncate_core::generation::generate_board(
truncate_core::generation::BoardSeed {
generation: 9999,
seed: (instant::SystemTime::now()
.duration_since(instant::SystemTime::UNIX_EPOCH)
.expect("Please don't play Truncate earlier than 1970")
.as_micros()
% 287520520) as u32,
day: None,
params: params.clone(),
current_iteration: 0,
width_resize_state: None,
height_resize_state: None,
water_level: 0.5,
max_attempts: 10000,
},
);
game.board = rand_board.expect("Board can be resolved").board;
game.board.cache_special_squares();
}
}

game.players[0].color = GAME_COLOR_BLUE;
game.players[1].color = GAME_COLOR_PURPLE;

board.cache_special_squares();
game.board = board.clone();

game.start();

let mut active_game = ActiveGame::new(
Expand Down
6 changes: 4 additions & 2 deletions truncate_core/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ impl Game {
p.turn_starts_no_later_than = Some(now);
p.turn_starts_no_sooner_than = Some(now);

self.game_ends_at = Some(now + total_time_allowance as u64);
if let Some(total_time_allowance) = total_time_allowance {
self.game_ends_at = Some(now + total_time_allowance as u64);
}
}),
_ => unimplemented!(),
}
Expand Down Expand Up @@ -166,7 +168,7 @@ impl Game {

match &self.rules.timing {
rules::Timing::Periodic {
total_time_allowance,
total_time_allowance: Some(total_time_allowance),
..
} => {
let elapsed = now() - started_at;
Expand Down
45 changes: 44 additions & 1 deletion truncate_core/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub enum Timing {
},
Periodic {
turn_delay: usize,
total_time_allowance: usize,
total_time_allowance: Option<usize>,
},
None,
}
Expand Down Expand Up @@ -229,4 +229,47 @@ impl GameRules {
}),
}
}

pub fn arcade() -> Self {
Self {
generation: None, // hydrated on fetch
win_condition: WinCondition::Destination {
town_defense: TownDefense::BeatenWithDefenseStrength(0),
},
win_metric: WinMetric::TownProximity,
visibility: Visibility::Standard,
truncation: Truncation::Root,
timing: Timing::Periodic {
turn_delay: 5,
total_time_allowance: None,
},
hand_size: 5,
tile_generation: 1,
tile_bag_behaviour: TileBagBehaviour::Standard,
battle_rules: BattleRules { length_delta: 2 },
swapping: Swapping::Contiguous(SwapPenalty::Disallowed { allowed_swaps: 1 }),
battle_delay: 2,
max_turns: None,
board_genesis: BoardGenesis::Random(BoardParams {
land_layer: BoardNoiseParams {
dispersion: [5.0, 5.0],
island_influence: 0.0,
symmetric: Symmetry::TwoFoldRotational,
},
water_layer: None,
land_dimensions: [9, 10],
canvas_dimensions: [18, 20],
maximum_town_density: 0.2,
maximum_town_distance: 0.15,
minimum_choke: 3,
dock_type: DockType::Coastal,
ideal_dock_extremity: 1.0,
elements: BoardElements {
docks: true,
towns: true,
obelisk: false,
},
}),
}
}
}
2 changes: 1 addition & 1 deletion truncate_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ async fn handle_player_msg(

match &game_manager.core_game.rules.timing {
truncate_core::rules::Timing::Periodic {
total_time_allowance,
total_time_allowance: Some(total_time_allowance),
..
} => {
tokio::spawn(check_game_over(
Expand Down

0 comments on commit bd746f6

Please sign in to comment.