influence test
This commit is contained in:
parent
067dc983d3
commit
58a5c6f20c
6 changed files with 151 additions and 14 deletions
46
server/.vscode/launch.json
vendored
Normal file
46
server/.vscode/launch.json
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug unit tests in library 'server'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"test",
|
||||
"--no-run",
|
||||
"--lib",
|
||||
"--package=server"
|
||||
],
|
||||
"filter": {
|
||||
"name": "server",
|
||||
"kind": "lib"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug integration test 'game_api_tests'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"test",
|
||||
"--no-run",
|
||||
"--test=game_api_tests",
|
||||
"--package=server"
|
||||
],
|
||||
"filter": {
|
||||
"name": "game_api_tests",
|
||||
"kind": "test"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ impl City {
|
|||
}
|
||||
|
||||
pub fn influenced(&self) -> bool {
|
||||
self.uninfluenced_buildings() as usize == self.city_pieces.amount()
|
||||
self.uninfluenced_buildings() as usize != self.city_pieces.amount()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +232,7 @@ impl CityData {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Hash, Clone)]
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Hash, Clone, Debug)]
|
||||
pub enum Building {
|
||||
Academy,
|
||||
Market,
|
||||
|
|
@ -397,7 +397,7 @@ pub enum MoodState {
|
|||
Angry,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
|
||||
pub struct AvailableBuildings {
|
||||
academies: u8,
|
||||
markets: u8,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ use super::custom_actions::CustomActionType::*;
|
|||
use crate::{civilization::Civilization, leader::Leader};
|
||||
|
||||
pub fn get_civilizations() -> Vec<Civilization> {
|
||||
vec![Civilization::new("test", vec![], vec![])]
|
||||
vec![
|
||||
Civilization::new("test0", vec![], vec![]),
|
||||
Civilization::new("test1", vec![], vec![]),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn get_civilization_by_name(name: &str) -> Option<Civilization> {
|
||||
|
|
|
|||
|
|
@ -514,7 +514,7 @@ pub struct GameData {
|
|||
wonder_amount_left: usize,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum GameState {
|
||||
Playing,
|
||||
StatusPhase(StatusPhaseState),
|
||||
|
|
@ -527,7 +527,7 @@ pub enum GameState {
|
|||
Finished,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum StatusPhaseState {
|
||||
CompleteObjectives,
|
||||
FreeAdvance,
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ impl PlayingAction {
|
|||
let target_city = game.players[target_player_index]
|
||||
.get_city(&target_city_position)
|
||||
.expect("Illegal action");
|
||||
let target_city_owner = target_city.player_index;
|
||||
let target_building_owner = target_city
|
||||
.city_pieces
|
||||
.building_owner(&city_piece)
|
||||
|
|
@ -122,9 +123,10 @@ impl PlayingAction {
|
|||
if matches!(&city_piece, Obelisk)
|
||||
|| starting_city.player_index != player_index
|
||||
|| !player.resources().can_afford(&range_boost_cost)
|
||||
|| (starting_city.influenced() && self_influence)
|
||||
|| (starting_city.influenced() && !self_influence)
|
||||
|| game.successful_cultural_influence
|
||||
|| !player.available_buildings.can_build(&city_piece)
|
||||
|| target_city_owner != target_player_index
|
||||
|| target_building_owner == player_index
|
||||
{
|
||||
panic!("Illegal action");
|
||||
|
|
@ -139,16 +141,15 @@ impl PlayingAction {
|
|||
&target_city_position,
|
||||
&city_piece,
|
||||
);
|
||||
return;
|
||||
}
|
||||
let roll_boost_cost = 5 - roll as u32;
|
||||
let can_afford_roll_boost_cost = game.players[player_index]
|
||||
if roll > 6 || self_influence || !game.players[player_index]
|
||||
.resources()
|
||||
.can_afford(&ResourcePile::culture_tokens(roll_boost_cost));
|
||||
if roll > 6 || self_influence || !can_afford_roll_boost_cost {
|
||||
.can_afford(&ResourcePile::culture_tokens(5 - roll as u32)) {
|
||||
return;
|
||||
}
|
||||
game.state = CulturalInfluenceResolution {
|
||||
roll_boost_cost,
|
||||
roll_boost_cost: 5 - roll as u32,
|
||||
target_player_index,
|
||||
target_city_position,
|
||||
city_piece,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use server::{
|
||||
city::{Building, City, MoodState::*},
|
||||
city::{AvailableBuildings, Building, City, MoodState::*},
|
||||
content::custom_actions::CustomAction::*,
|
||||
game::Action,
|
||||
game::{Action, GameState::*},
|
||||
game_api,
|
||||
hexagon::Position,
|
||||
playing_actions::PlayingAction::*,
|
||||
|
|
@ -56,6 +56,11 @@ fn one_player() {
|
|||
let game = game_api::execute_action(game, construct_action, 0);
|
||||
let player = &game.players[0];
|
||||
|
||||
assert_eq!(
|
||||
AvailableBuildings::new(5, 5, 5, 4, 5, 5, 5),
|
||||
player.available_buildings
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Some(0),
|
||||
player
|
||||
|
|
@ -118,3 +123,85 @@ fn one_player() {
|
|||
);
|
||||
assert_eq!(1, game.actions_left);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cultural_influence() {
|
||||
let mut game = game_api::init(2, String::new());
|
||||
game.dice_roll_outcomes = vec![6, 4, 5, 3, 7];
|
||||
game.current_player_index = 0;
|
||||
game.players[0].gain_resources(ResourcePile::culture_tokens(4));
|
||||
game.players[1].gain_resources(ResourcePile::culture_tokens(1));
|
||||
let city0position = Position::new(0, 0);
|
||||
let city1position = Position::new(2, 0);
|
||||
assert_eq!(city0position.distance(&city1position), 2);
|
||||
game.players[0]
|
||||
.cities
|
||||
.push(City::new(0, city0position.clone()));
|
||||
game.players[1]
|
||||
.cities
|
||||
.push(City::new(1, city1position.clone()));
|
||||
game.players[1].construct(&Building::Academy, &city1position);
|
||||
let influence_action = Action::PlayingAction(InfluenceCultureAttempt {
|
||||
starting_city_position: city0position.clone(),
|
||||
target_player_index: 1,
|
||||
target_city_position: city1position.clone(),
|
||||
city_piece: Building::Academy,
|
||||
});
|
||||
let game = game_api::execute_action(game, influence_action, 0);
|
||||
assert!(!game.players[1].cities[0].influenced());
|
||||
assert_eq!(game.state, Playing);
|
||||
let influence_action = Action::PlayingAction(InfluenceCultureAttempt {
|
||||
starting_city_position: city0position.clone(),
|
||||
target_player_index: 1,
|
||||
target_city_position: city1position.clone(),
|
||||
city_piece: Building::Academy,
|
||||
});
|
||||
let game = game_api::execute_action(game, influence_action, 0);
|
||||
assert!(!game.players[1].cities[0].influenced());
|
||||
assert_eq!(
|
||||
game.state,
|
||||
CulturalInfluenceResolution {
|
||||
roll_boost_cost: 2,
|
||||
target_player_index: 1,
|
||||
target_city_position: city1position.clone(),
|
||||
city_piece: Building::Academy
|
||||
}
|
||||
);
|
||||
let influence_resolution_decline_action = Action::CulturalInfluenceResolutionAction(false);
|
||||
let game = game_api::execute_action(game, influence_resolution_decline_action, 0);
|
||||
assert!(!game.players[1].cities[0].influenced());
|
||||
assert_eq!(game.state, Playing);
|
||||
assert!(!game.successful_cultural_influence);
|
||||
let influence_action = Action::PlayingAction(InfluenceCultureAttempt {
|
||||
starting_city_position: city0position,
|
||||
target_player_index: 1,
|
||||
target_city_position: city1position.clone(),
|
||||
city_piece: Building::Academy,
|
||||
});
|
||||
let game = game_api::execute_action(game, influence_action, 0);
|
||||
assert!(game.players[1].cities[0].influenced());
|
||||
assert_eq!(game.state, Playing);
|
||||
assert!(game.successful_cultural_influence);
|
||||
let game = game_api::execute_action(game, Action::PlayingAction(EndTurn), 0);
|
||||
assert_eq!(game.current_player_index, 1);
|
||||
let influence_action = Action::PlayingAction(InfluenceCultureAttempt {
|
||||
starting_city_position: city1position.clone(),
|
||||
target_player_index: 1,
|
||||
target_city_position: city1position.clone(),
|
||||
city_piece: Building::Academy,
|
||||
});
|
||||
let game = game_api::execute_action(game, influence_action, 1);
|
||||
assert!(game.players[1].cities[0].influenced());
|
||||
assert_eq!(game.state, Playing);
|
||||
assert!(!game.successful_cultural_influence);
|
||||
let influence_action = Action::PlayingAction(InfluenceCultureAttempt {
|
||||
starting_city_position: city1position.clone(),
|
||||
target_player_index: 1,
|
||||
target_city_position: city1position,
|
||||
city_piece: Building::Academy,
|
||||
});
|
||||
let game = game_api::execute_action(game, influence_action, 1);
|
||||
assert!(!game.players[1].cities[0].influenced());
|
||||
assert_eq!(game.state, Playing);
|
||||
assert!(game.successful_cultural_influence);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue