Skip to content

Commit

Permalink
Merge pull request #44 from Trisfald/rename-rounds
Browse files Browse the repository at this point in the history
swap rounds and turns
  • Loading branch information
Trisfald authored Aug 14, 2020
2 parents e7bfa58 + 3898ea2 commit c213ce3
Show file tree
Hide file tree
Showing 43 changed files with 467 additions and 464 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Rounds and turns now reflect the most used definition (a round is made of multiple turns).
- Renamed `StartRound` into `StartTurn`, swapped `EndRound` and `EndTurn` and renamed `EnvironmentRound` into `EnvironmentTurn`.
- Renamed `check_objectives_on_round` into `check_objectives_on_turn`.
- Renamed `on_round_start` into `on_turn_start` and `on_round_end` into `on_turn_end`.
- Renamed `RoundState` into `TurnState`.

## [0.8.1] - 2020-08-12
### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ weasel provides many functionalities to ease the development of a turn based gam
- Long lasting status effects.
- Player managed teams.
- Team objectives and diplomacy.
- Division of the battle into rounds.
- Division of the battle into turns and rounds.
- Rules to govern the game subdivided into orthogonal traits.
- Fully serializable battle history.
- Cause-effect relationship between events.
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Example program showing the different ways to manage the space dimension in weas

## [Initiative](initiative/)

A simple implementation of `RoundsRules` to decide the order of rounds based on a creature's statistic.
A simple implementation of `RoundsRules` to decide the order of turns based on a creature's statistic.

## [Undo](undo/)

Expand Down
2 changes: 1 addition & 1 deletion examples/initiative/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This example shows how to implement `RoundsRules` to decide the order of acting during a battle.

The first step is to create five creatures, each one with a different value of *speed*. Then, we will repeatedly start and end rounds while also displaying the global order of initiative.
The first step is to create five creatures, each one with a different value of *speed*. Then, we will repeatedly start and end turns while also displaying the global order of initiative.

Run the example with:
```
Expand Down
28 changes: 14 additions & 14 deletions examples/initiative/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::rules::*;
use std::time::SystemTime;
use weasel::team::TeamId;
use weasel::{
Battle, BattleController, CreateCreature, CreateTeam, EndRound, EventTrigger, RemoveCreature,
ResetEntropy, Server, StartRound,
Battle, BattleController, CreateCreature, CreateTeam, EndTurn, EventTrigger, RemoveCreature,
ResetEntropy, Server, StartTurn,
};

mod rules;
Expand Down Expand Up @@ -31,23 +31,23 @@ fn main() {
.fire()
.unwrap();
}
// Carry out five rounds.
// Carry out five turn.
for _ in 0..5 {
round(&mut server);
turn(&mut server);
}
// Remove one creature.
println!("Creature (1) removed!");
println!();
RemoveCreature::trigger(&mut server, 1).fire().unwrap();
// Do a final round.
round(&mut server);
// Do a final turn.
turn(&mut server);
}

fn round(server: &mut Server<CustomRules>) {
// Display in which round we are.
fn turn(server: &mut Server<CustomRules>) {
// Display in which turn we are.
println!(
"Round {} - Initiative table:",
server.battle().rounds().completed_rounds() + 1
"Turn {} - Initiative table:",
server.battle().rounds().completed_turns() + 1
);
println!();
// Display the order of initiative.
Expand All @@ -58,8 +58,8 @@ fn round(server: &mut Server<CustomRules>) {
let actor_id = initiative.top();
println!("It's the turn of: {}", actor_id);
println!();
// Start the round.
StartRound::trigger(server, actor_id).fire().unwrap();
// Since this's an example, creatures do nothing and immediately end the round.
EndRound::trigger(server).fire().unwrap();
// Start the turn.
StartTurn::trigger(server, actor_id).fire().unwrap();
// Since this's an example, creatures do nothing and immediately end the turn.
EndTurn::trigger(server).fire().unwrap();
}
30 changes: 15 additions & 15 deletions examples/king_of_the_hill/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use weasel::team::TeamId;
use weasel::{
ActivateAbility, Actor, Battle, BattleController, BattleState, Character, CreateCreature,
CreateTeam, Creature, EndRound, EndTurn, EntityId, EventKind, EventProcessor, EventQueue,
EventTrigger, EventWrapper, Id, RemoveEntity, ResetObjectives, Server, StartRound,
EventTrigger, EventWrapper, Id, RemoveEntity, ResetObjectives, Server, StartTurn,
};

mod rules;
Expand Down Expand Up @@ -81,7 +81,7 @@ fn server_game_loop(mut server: TcpServer) {
game_status(server.game_server.lock().unwrap().battle(), id);
loop {
// Check for the game's end.
if completed_turns(&server.game_server) == 3 {
if completed_rounds(&server.game_server) == 3 {
println!("The game has ended!");
return;
}
Expand All @@ -105,9 +105,9 @@ fn server_game_loop(mut server: TcpServer) {
fn client_game_loop(mut client: TcpClient) {
game_status(client.game_client.lock().unwrap().battle(), client.id);
loop {
let turn = completed_turns(&client.game_client);
let round = completed_rounds(&client.game_client);
// Check for the game's end.
if turn == 3 {
if round == 3 {
println!("The game has ended!");
return;
}
Expand All @@ -119,16 +119,16 @@ fn client_game_loop(mut client: TcpClient) {
key.to_digit(10).unwrap(),
client.id,
) {
// Wait for the turn completion.
// Wait for the round completion.
wait(|| {
client
.game_client
.lock()
.unwrap()
.battle()
.rounds()
.completed_turns()
> turn
.completed_rounds()
> round
});
game_status(client.game_client.lock().unwrap().battle(), client.id);
}
Expand Down Expand Up @@ -198,18 +198,18 @@ where
// each event to be acknowledged. A proper solution would be to have the server sending
// messages to the clients and the clients themselves having a state machine.
let last_event = controller.lock().unwrap().battle().history().len();
StartRound::trigger(&mut *controller.lock().unwrap(), card_id)
StartTurn::trigger(&mut *controller.lock().unwrap(), card_id)
.fire()
.unwrap();
// Wait to receive the StartRound event validation.
// Wait to receive the StartTurn event validation.
wait(|| controller.lock().unwrap().battle().history().len() > last_event);
let last_event = controller.lock().unwrap().battle().history().len();
ActivateAbility::trigger(&mut *controller.lock().unwrap(), card_id, PLAY_CARD_ABILITY)
.fire()
.unwrap();
// Wait to receive the ActivateAbility and MoveEntity events validation.
wait(|| controller.lock().unwrap().battle().history().len() > last_event + 1);
EndRound::trigger(&mut *controller.lock().unwrap())
EndTurn::trigger(&mut *controller.lock().unwrap())
.fire()
.unwrap();
true
Expand Down Expand Up @@ -240,14 +240,14 @@ fn server_end_turn(server: &mut Arc<Mutex<Server<CustomRules>>>) {
.fire()
.unwrap();
}
// Close the turn.
EndTurn::trigger(&mut *server.lock().unwrap())
// Close the round.
EndRound::trigger(&mut *server.lock().unwrap())
.fire()
.unwrap();
}

/// Returns the number of completed turns.
fn completed_turns<T>(controller: &Arc<Mutex<T>>) -> TurnsCount
/// Returns the number of completed rounds.
fn completed_rounds<T>(controller: &Arc<Mutex<T>>) -> TurnsCount
where
T: BattleController<CustomRules> + EventProcessor<CustomRules>,
{
Expand All @@ -256,7 +256,7 @@ where
.unwrap()
.battle()
.rounds()
.completed_turns()
.completed_rounds()
}

/// Method to decide who won a turn.
Expand Down
2 changes: 1 addition & 1 deletion examples/king_of_the_hill/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl RoundsRules<CustomRules> for MyRoundsRules {
_: &mut Entropy<CustomRules>,
_: &mut WriteMetrics<CustomRules>,
) {
// When a player round end bump the counter, wrapping at 3
// When a player turn ends bump the counter, wrapping at 3
// so that it cycles between 0, 1 and 2.
*model = (*model + 1) % 3;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/passive/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Passive

In this example we implement a simple passive ability. This skill increases the power of another ability at every round.
In this example we implement a simple passive ability. This skill increases the power of another ability at every turn.

At the start we'll spawn two soldiers. Both of them known the ability *punch*, but only one has the passive ability *power up*.

Every time the soldier ends his round, *power up* increases the power of *punch* by one times the number of creatures on the battlefield.
Every time the soldier ends his turn, *power up* increases the power of *punch* by one times the number of creatures on the battlefield.

Run the example with:
```
Expand Down
36 changes: 19 additions & 17 deletions examples/passive/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::rules::*;
use weasel::creature::CreatureId;
use weasel::team::TeamId;
use weasel::{
Actor, Battle, BattleController, CreateCreature, CreateTeam, EndRound, Entity, EntityId,
EventTrigger, Server, StartRound,
Actor, Battle, BattleController, CreateCreature, CreateTeam, EndTurn, Entity, EntityId,
EventTrigger, Server, StartTurn,
};

mod rules;
Expand Down Expand Up @@ -32,29 +32,31 @@ fn main() {
.abilities_seed(vec![PUNCH, POWER_UP])
.fire()
.unwrap();
println!("Now doing three turns of combat. Notice how Creature (2) punches get more powerful!");
println!(
"Now doing three rounds of combat. Notice how Creature (2) punches get more powerful!"
);
println!();
// Carry out three turns.
// Carry out three round.
for i in 0..3 {
turn(&mut server, i);
round(&mut server, i);
}
}

/// Does a turn, containing a round for each creatures.
fn turn(server: &mut Server<CustomRules>, turn: u32) {
// Display in which turn we are.
println!("Turn {}", turn + 1);
/// Does a round, containing a turn for each creatures.
fn round(server: &mut Server<CustomRules>, turn: u32) {
// Display in which round we are.
println!("Round {}", turn + 1);
println!();
print_power(server, CREATURE_1_ID);
print_power(server, CREATURE_2_ID);
// Start and end a round for the first creature.
println!("Round of Creature (1)...");
StartRound::trigger(server, ENTITY_1_ID).fire().unwrap();
EndRound::trigger(server).fire().unwrap();
// Start and end a round for the second creature.
println!("Round of Creature (2)...");
StartRound::trigger(server, ENTITY_2_ID).fire().unwrap();
EndRound::trigger(server).fire().unwrap();
// Start and end a turn for the first creature.
println!("Turn of Creature (1)...");
StartTurn::trigger(server, ENTITY_1_ID).fire().unwrap();
EndTurn::trigger(server).fire().unwrap();
// Start and end a turn for the second creature.
println!("Turn of Creature (2)...");
StartTurn::trigger(server, ENTITY_2_ID).fire().unwrap();
EndTurn::trigger(server).fire().unwrap();
print_power(server, CREATURE_1_ID);
print_power(server, CREATURE_2_ID);
println!();
Expand Down
2 changes: 1 addition & 1 deletion examples/passive/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl ActorRules<CustomRules> for CustomActorRules {
}
}

fn on_round_end(
fn on_turn_end(
&self,
state: &BattleState<CustomRules>,
actor: &dyn Actor<CustomRules>,
Expand Down
28 changes: 14 additions & 14 deletions examples/pirates/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use weasel::creature::CreatureId;
use weasel::team::TeamId;
use weasel::{
ActivateAbility, AlterStatistics, Battle, BattleController, BattleState, Character,
CreateCreature, CreateTeam, EndBattle, EndRound, EntityId, EventKind, EventQueue,
EventReceiver, EventTrigger, EventWrapper, FlatVersionedEvent, RemoveCreature, ResetEntropy,
Server, StartRound,
CreateCreature, CreateTeam, EndBattle, EndTurn, EntityId, EventKind, EventQueue, EventReceiver,
EventTrigger, EventWrapper, FlatVersionedEvent, RemoveCreature, ResetEntropy, Server,
StartTurn,
};

// Constants to identify teams.
Expand Down Expand Up @@ -70,8 +70,8 @@ impl Game {
}

pub fn fire_cannonball(&mut self) {
// Before our ship can attack we must start a player round.
StartRound::trigger(&mut self.server, EntityId::Creature(PLAYER_SHIP))
// Before our ship can attack we must start a player turn.
StartTurn::trigger(&mut self.server, EntityId::Creature(PLAYER_SHIP))
.fire()
.unwrap();
// Now activate the 'cannonball' ability of the player's ship.
Expand All @@ -85,13 +85,13 @@ impl Game {
.activation(EntityId::Creature(ENEMY_SHIP))
.fire()
.unwrap();
// After the ship's attack we just end the player round.
EndRound::trigger(&mut self.server).fire().unwrap();
// After the ship's attack we just end the player turn.
EndTurn::trigger(&mut self.server).fire().unwrap();
}

pub fn fire_grapeshot(&mut self) {
// Some logic as fire_cannonball, but fire another ability.
StartRound::trigger(&mut self.server, EntityId::Creature(PLAYER_SHIP))
StartTurn::trigger(&mut self.server, EntityId::Creature(PLAYER_SHIP))
.fire()
.unwrap();
ActivateAbility::trigger(
Expand All @@ -102,12 +102,12 @@ impl Game {
.activation(EntityId::Creature(ENEMY_SHIP))
.fire()
.unwrap();
EndRound::trigger(&mut self.server).fire().unwrap();
EndTurn::trigger(&mut self.server).fire().unwrap();
}

pub fn enemy_round(&mut self) {
// Before the enemy ship can attack we must start an enemy round.
StartRound::trigger(&mut self.server, EntityId::Creature(ENEMY_SHIP))
pub fn enemy_turn(&mut self) {
// Before the enemy ship can attack we must start an enemy turn.
StartTurn::trigger(&mut self.server, EntityId::Creature(ENEMY_SHIP))
.fire()
.unwrap();
// Fire a random ability.
Expand All @@ -126,8 +126,8 @@ impl Game {
.activation(EntityId::Creature(PLAYER_SHIP))
.fire()
.unwrap();
// After the ship's attack we just end the enemy round.
EndRound::trigger(&mut self.server).fire().unwrap();
// After the ship's attack we just end the enemy turn.
EndTurn::trigger(&mut self.server).fire().unwrap();
}

/// Saves the battle's history as json in a temporary file.
Expand Down
4 changes: 2 additions & 2 deletions examples/pirates/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn game_loop() {
if game.check_winner() {
break;
}
game.enemy_round();
game.enemy_turn();
if game.check_winner() {
break;
}
Expand All @@ -70,7 +70,7 @@ fn game_loop() {
if game.check_winner() {
break;
}
game.enemy_round();
game.enemy_turn();
if game.check_winner() {
break;
}
Expand Down
6 changes: 3 additions & 3 deletions examples/pirates/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ impl TeamRules<PiratesRules> for PiratesTeamRules {
seed.as_ref().unwrap().clone()
}

// We override the function to check objectives each time a round is finished.
fn check_objectives_on_round(
// We override the function to check objectives each time a turn is finished.
fn check_objectives_on_turn(
&self,
state: &BattleState<PiratesRules>,
team: &Team<PiratesRules>,
Expand Down Expand Up @@ -215,7 +215,7 @@ battle_rules! {
EmptyUserRules,
// In our game ships don't move.
EmptySpaceRules,
// We handle rounds manually. The player always goes first.
// We handle turns manually. The player always goes first.
EmptyRoundsRules,
UniformDistribution<i16>
}
Expand Down
Loading

0 comments on commit c213ce3

Please sign in to comment.