flip coin
This commit is contained in:
parent
ad3635e275
commit
6f504acf12
|
|
@ -1,9 +1,9 @@
|
|||
use std::{net::UdpSocket, time::SystemTime};
|
||||
|
||||
use renet::transport::{NetcodeClientTransport, NetcodeTransportError, NETCODE_USER_DATA_BYTES};
|
||||
use store::{EndGameReason, GameEvent, GameState};
|
||||
use store::{GameEvent, GameState};
|
||||
|
||||
use bevy::{prelude::*, utils::HashMap};
|
||||
use bevy::{prelude::*};
|
||||
use bevy::window::PrimaryWindow;
|
||||
use bevy_renet::{
|
||||
renet::{transport::ClientAuthentication, ConnectionConfig, RenetClient},
|
||||
|
|
@ -123,7 +123,7 @@ fn update_board(
|
|||
) {
|
||||
for event in game_events.iter() {
|
||||
match event.0 {
|
||||
GameEvent::Move { player_id, from, to } => {
|
||||
GameEvent::Move { player_id, from: _, to } => {
|
||||
// backgammon postions, TODO : dépend de player_id
|
||||
let (x, y) = if to < 13 { (13 - to, 1) } else { (to - 13, 0)};
|
||||
let texture =
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ fn main() {
|
|||
trace!("The game gas begun");
|
||||
}
|
||||
}
|
||||
ServerEvent::ClientDisconnected { client_id, reason } => {
|
||||
ServerEvent::ClientDisconnected { client_id, reason: _ } => {
|
||||
// First consume a disconnect event
|
||||
let event = store::GameEvent::PlayerDisconnected {
|
||||
player_id: client_id,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,14 @@ impl Dices {
|
|||
}
|
||||
}
|
||||
|
||||
/// Heads or tails
|
||||
pub fn coin(self) -> bool {
|
||||
let between = Uniform::new_inclusive(1, 2);
|
||||
let mut rng = rand::thread_rng();
|
||||
between.sample(&mut rng) == 1
|
||||
}
|
||||
|
||||
|
||||
pub fn to_bits_string(self) -> String {
|
||||
format!("{:0>3b}{:0>3b}", self.values.0, self.values.1)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ use crate::board::{Board, Move};
|
|||
use crate::dice::{Dices, Roll};
|
||||
use crate::player::{Color, Player, PlayerId};
|
||||
use crate::Error;
|
||||
use log::{error, info, trace, warn};
|
||||
use log::{error};
|
||||
|
||||
// use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::{fmt, vec, str};
|
||||
use std::{fmt, str};
|
||||
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
|
||||
|
|
@ -79,14 +79,6 @@ impl GameState {
|
|||
self.players.insert(player_id, player);
|
||||
}
|
||||
|
||||
/// Format to TGPN notation (Tables games position notation)
|
||||
// fn toTGPN(&self, f: &mut fmt::Formatter) -> TGPN {
|
||||
pub fn toTGPN(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut s = String::new();
|
||||
// s.push_str(&format!("Dices: {:?}\n", self.dices));
|
||||
write!(f, "{}", s)
|
||||
}
|
||||
|
||||
/// Calculate game state id :
|
||||
pub fn to_string_id(&self) -> String {
|
||||
// Pieces placement -> 77 bits (24 + 23 + 30 max)
|
||||
|
|
@ -282,7 +274,7 @@ impl GameState {
|
|||
PlayerDisconnected { player_id } => {
|
||||
self.players.remove(player_id);
|
||||
}
|
||||
Roll { player_id } => {}
|
||||
Roll { player_id: _ } => {}
|
||||
Move {
|
||||
player_id,
|
||||
from,
|
||||
|
|
@ -348,8 +340,10 @@ impl Roll for GameState {
|
|||
fn roll(&mut self) -> Result<&mut Self, Error> {
|
||||
self.dices = self.dices.roll();
|
||||
if self.who_plays().is_none() {
|
||||
let diff = self.dices.values.0 - self.dices.values.1;
|
||||
let active_color = if diff < 0 { Color::Black } else { Color::White };
|
||||
let active_color = match self.dices.coin() {
|
||||
false => Color::Black,
|
||||
true => Color::White
|
||||
};
|
||||
let color_player_id = self.player_id_by_color(active_color);
|
||||
if color_player_id.is_some() {
|
||||
self.active_player_id = *color_player_id.unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue