src/main.rs
author Peter Gervai <grin@grin.hu>
Tue, 31 Jan 2023 23:25:50 +0100
changeset 4 a2f0cb2b5c13
parent 3 3d9dba5b16e0
child 5 0dd7f2c9fd81
permissions -rw-r--r--
Split main into module files.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
     1
// #[allow(dead_code, unused)]
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     2
// vigyazz6! autplayer
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     3
//
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     4
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
     5
use core::panic;
3
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
     6
use std::{collections::VecDeque, time::Instant, cmp::Reverse};
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
     7
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
     8
use crate::{deck::Deck, player::Player, table::Table};
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
     9
// use rand::Rng;
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    10
// use std::mem;
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    11
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    12
mod deck;
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    13
mod table;
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    14
mod player;
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    15
mod card;
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    16
mod row;
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    17
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    18
extern crate pretty_env_logger;
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    19
#[macro_use] extern crate log;
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    20
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    21
const GAME_ROUNDS: i32 = 100_000;
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    22
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    23
fn main() {
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    24
    // RUST_LOG=debug cargo run
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    25
    pretty_env_logger::init();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    26
    info!("Program starting.");
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    27
    game();
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    28
    info!("End of run.");
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    29
}
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    30
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    31
// Card
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    32
// Deck
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    33
// Player
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
    34
// Row
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    35
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    36
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    37
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    38
/*** Game ****/
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    39
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    40
struct GameStat {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    41
    game_count: i64,
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    42
    shuffle_count: i64,
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    43
    start_time: Instant, // use start_time.elapsed().as_nanos() or .as_secs()
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    44
}
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    45
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    46
fn game() {
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    47
    let mut stats = GameStat { game_count:0, shuffle_count: 0, start_time: Instant::now() };
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    48
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    49
    let mut deck = Deck::new();
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    50
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    51
    let player_names = vec![ "grin", "moni", "icbalint", "orsi", "topi", "kgb", "zsu", "csilla" ];
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    52
    let mut players: Vec<Player> = player_names.iter().map( |n| Player::new(n.to_string()) ).collect();
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    53
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    54
    let player_count = players.len(); // pc - 1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    55
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    56
    for cnt_game in 1..=GAME_ROUNDS {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    57
        debug!("Game round {} starts", cnt_game);
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    58
        deck.shuffle();
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    59
        stats.shuffle_count += 1;
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    60
        stats.game_count += 1;
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    61
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    62
        // dealing
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    63
        debug!("Dealing.");
3
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    64
        for _i in 1..=10 {
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    65
            for player in 0 .. player_count {
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    66
                players[player].get_card( deck.pop().expect("Deck is empty while dealing to players") );
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    67
            }
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    68
        }
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    69
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    70
        // we need 5 crds from deck
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    71
        debug!("Building the rows.");
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    72
        let mut cards = VecDeque::new();
3
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    73
        (1..=5).for_each(|_| {
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    74
            cards.push_back( deck.pop().expect("deck empty before starting the game") );
3
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
    75
        });
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    76
        // println!("We push 5 cards to rows: {:?}\n", cards);
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    77
        let mut table = Table::new(cards);
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    78
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    79
        // DEBUG
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    80
/*         println!("Table: {:?}\n", table);
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    81
        println!("PLayers: {:?}\n", players);
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    82
        println!("Deck: {:?}\n", deck);
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    83
 */        
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    84
        debug!("We have the table ready: {:?}", table);
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    85
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    86
        // playing
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    87
        debug!("Players start taking turns");
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    88
        for turn in 1..=10 {
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    89
            debug!("Turn {}!", turn);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
    90
            trace!("The table: {:?}", table);
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    91
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    92
            // everyone puts a card face down
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    93
            for player in 0 .. player_count {
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    94
                let player_id: i32 = player.try_into().unwrap();
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    95
                // get a card from the player
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    96
                let topcard = players[player].throw_card();
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    97
                // put it on the table ("turned face down")
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    98
                table.lay_player_card( topcard, player_id );
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    99
            }
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   100
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   101
            // process cards
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   102
            debug!("The Table process the throws.");
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   103
            table.sort_cards();
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   104
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   105
            while table.has_player_cards() {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   106
                let smallest = table.get_smallest_player_card();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   107
                trace!("Take smallest card {:?}", &smallest);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   108
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   109
                let closest_row = table.get_closest_row(&smallest);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   110
                trace!("Choose closest row: {:?}", closest_row);
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   111
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   112
                match closest_row {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   113
                    Some(rowid) => {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   114
                        debug!("Putting down card into row {}", rowid);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   115
                        let player_id: usize = smallest.player_id.try_into().unwrap();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   116
                        let overflow = table.put_card_into_row(smallest, rowid);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   117
                        if let Some(cards) = overflow {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   118
                            // row is full, got pile
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   119
                            debug!("Row is busted, {} collects", players[player_id].get_name());
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   120
                            // player gets pile, card gets into row head
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   121
                            players[ player_id ].give_pile( cards );
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   122
                        }
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   123
                    },
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   124
                    None => {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   125
                        // card too small, need to pick row!
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   126
                        let player_id: usize = smallest.player_id.try_into().unwrap();
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   127
                        debug!("Too small from {}, picking row", players[player_id].get_name());
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   128
                        // pick any row to take
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   129
                        // let rowid = players[ player_id ].pick_row_for_small_card(&table.rows, &smallest.card);
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   130
                        let rowid = players[ player_id ].pick_row_for_small_card(table.peek_rows(), &smallest.card);
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   131
                        trace!("Picked row {}", rowid);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   132
                        // take the row cards
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   133
                        let cards = table.take_row(rowid);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   134
                        trace!("Took cards: {:?}", cards);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   135
                        players[ player_id ].give_pile( cards );
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   136
                        // put new card in the row
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   137
                        let overflow = table.put_card_into_row(smallest, rowid);
3
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
   138
                        if let Some(_) = overflow {
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   139
                            panic!("Player took whole row and it's already full");
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   140
                        }
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   141
                    }
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   142
                }
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   143
            }
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   144
        }
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   145
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   146
        // end of round
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   147
        info!("Round finished, len is {} ??sec", stats.start_time.elapsed().as_micros());
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   148
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   149
        debug!("End of round, counting and collecting back piles");
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   150
        let mut winners: Vec<usize> = Vec::new();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   151
        let mut winscore: i32 = i32::MAX-1;
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   152
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   153
        for i in 0..player_count {
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   154
            info!("Player {} has {} points", players[i].get_name(), players[i].get_points());
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   155
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   156
            if players[i].get_points() < winscore  {
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   157
                trace!("New winner {} with score {}", players[i].get_name(), players[i].get_points());
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   158
                winners.clear();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   159
                winners.push(i);
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   160
                winscore = players[i].get_points();
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   161
            
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   162
            } else if players[i].get_points() == winscore {
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   163
                trace!("New co-winner {} with score {}", players[i].get_name(), players[i].get_points());
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   164
                winners.push(i);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   165
            }
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   166
            trace!("The list of winners is {:?}", winners);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   167
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   168
            // get pile from player
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   169
            let cards = players[i].get_pile();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   170
            // and give it back to the deck
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   171
            deck.push_cards(cards);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   172
            // close player round and update stats
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   173
            players[i].close_round();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   174
        }
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   175
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   176
        // collect cards from table
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   177
        deck.push_cards( table.collect_rows() );
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   178
        trace!("Shall have full deck now, len {}", deck.len());
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   179
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   180
        let mut finals = Vec::new();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   181
        for i in winners.iter() {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   182
            players[*i].inc_wins();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   183
        }
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   184
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   185
        for i in winners {
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   186
            finals.push( players[i].get_name() );
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   187
        }
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   188
        info!("The winner(s): {:?}", &finals);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   189
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   190
/*         players.iter().for_each(|player| {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   191
            println!("Player {} has {} points", player.name, player.game_point);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   192
            let cards = player.get_pile();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   193
            deck.push_cards(cards);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   194
            player.close_round();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   195
        });
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   196
 */
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   197
    }
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   198
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   199
    // do the type conversions _very_ visibly 
3
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
   200
    let elapsed_micro: f64 = stats.start_time.elapsed().as_micros() as f64;
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
   201
    let game_rounds: f64 = GAME_ROUNDS.into();
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   202
    // which is same as the slightly uglier
3
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
   203
    let _res: f64 = stats.start_time.elapsed().as_micros() as f64 / <i32 as Into<f64>>::into(GAME_ROUNDS);
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
   204
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
   205
    println!("Totals (game time {} ??s, or {} s; {} ??s/game), {} games played ({} shuffles):", 
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   206
        stats.start_time.elapsed().as_micros(), 
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   207
        stats.start_time.elapsed().as_secs(),
3
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
   208
        elapsed_micro / game_rounds, 
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   209
        stats.game_count,
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   210
        stats.shuffle_count,
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   211
    );
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   212
3
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
   213
    // players.sort_by( |a, b| a.total_point.partial_cmp(&b.total_point).unwrap() );    // ASC points
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
   214
    // players.sort_by( |a, b| b.wins.partial_cmp(&a.wins).unwrap() );                  // DESC wins
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   215
    players.sort_by_cached_key( |x| Reverse(x.get_wins()) );                                  // DESC wins (caching is just for the show)
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   216
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   217
    for i in 0..players.len() {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   218
        let p = &players[i];
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   219
        println!("Player {} has wins {}, score {} (busted {} times)", 
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   220
            p.get_name(), 
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   221
            p.get_wins(), 
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   222
            p.get_total_points(), 
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   223
            p.get_rows_busted());
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   224
    }
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   225
}
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   226
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   227
#[cfg(test)]
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   228
mod tests {
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   229
    use std::collections::VecDeque;
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   230
    use rand::Rng;
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   231
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   232
    use crate::{card::Card, player::{Player, PlayerCard}, row::Row, table::Table};
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   233
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   234
    #[test]
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   235
    fn card_values() {
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   236
        let card_values = vec![1,2,5,10,33,55,77];
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   237
        let card_points = vec![1,1,2,3, 5, 7, 5];
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   238
        for i in 1 .. card_values.len() {
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   239
            let c = Card::new( card_values[i] );
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   240
            let p = c.points;
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   241
            assert!(p == card_points[i], "card={} card points={} i={} expected point={}", card_values[i], p, i, card_points[i]);
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   242
        }
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   243
    }
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   244
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   245
    #[test]
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   246
    fn player_take_pile() {
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   247
        // create a player
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   248
        let mut p = Player::new("bob".to_string());
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   249
        // create a pile
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   250
        let mut pile = VecDeque::new();
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   251
        let mut refpile = VecDeque::new();
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   252
        for i in 5..10 {
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   253
            let c = Card::new(i);
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   254
            pile.push_back(c);
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   255
            let c = Card::new(i);
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   256
            refpile.push_back(c);
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   257
        }
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   258
        // give the pile to player
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   259
        p.give_pile(pile);
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   260
        assert!( p.get_rows_busted() == 1 );
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   261
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   262
        // get back the pile from player
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   263
        // p = p.gimme_pile();
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   264
        let pile = p.get_pile();
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   265
        
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   266
        // the pile we got shall be same as the pile we gave
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   267
        // this check is O(n^2), doesn't matter for less than 100 items
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   268
        assert_eq!( pile, refpile );
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   269
        assert!( pile.iter().all( |item| refpile.contains(item)) );
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   270
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   271
        let mut pile = VecDeque::new();
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   272
        for i in 4..=9 {
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   273
            let c = Card::new(i);
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   274
            pile.push_back(c);
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   275
        }
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   276
        p.give_pile(pile);
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   277
        assert!( p.get_rows_busted() == 2 );
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   278
    }
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   279
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   280
    #[test]
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   281
    fn row_push() {
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   282
        let mut row = Row::new();
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   283
        let mut refcard = VecDeque::new();   // reference vec to check
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   284
        for i in 1..=7 {
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   285
            let cval = i+5;
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   286
            let card = Card::new(cval);
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   287
            // push a card into the row
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   288
            if let Some(cards) = row.push_or_collect(card) {
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   289
                // got the overflow
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   290
                println!("Got overflow row at {}!", i);
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   291
                assert!( i == 6, "Overflow at wrong position: {} != 6", i );
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   292
                // we need to get the proper vec
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   293
                assert!( cards.iter().all( |item| refcard.contains(item) ), "Got cards {:?}", cards ); 
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   294
            } else {
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   295
                println!("push success {}", i);
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   296
            }
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   297
            // remember the correct vec for checking
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   298
            let card = Card::new(cval);
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   299
            refcard.push_back(card);
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   300
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   301
            // check card value
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   302
            assert!( row.last_card_value() == cval, "Last card value mismatch: got {} vs expected {}", row.last_card_value(), cval );
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   303
        }
4
a2f0cb2b5c13 Split main into module files.
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
   304
        assert!( row.len() == 2, "Row contains wrong amount of cards: {}", row.len() );
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   305
    }
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   306
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   307
    #[test]
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   308
    fn sort_cards() {
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   309
        let mut cards: VecDeque<Card> = VecDeque::new();
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   310
        let mut rng = rand::thread_rng();
3
3d9dba5b16e0 v1.00 - single file
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
   311
        for _ in 1..50 {
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   312
            let n = rng.gen_range(1..104);
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   313
            cards.push_back( Card::new(n) );
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   314
        }
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   315
        cards.make_contiguous().sort();
1
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   316
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   317
        for i in 1..cards.len() {
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   318
            assert!( cards[i-1].value <= cards[i].value, "Bad ordering: {} > {}", cards[i-1].value,cards[i].value );
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   319
        }
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   320
    }
5f81068a8a88 Progressing....
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
   321
2
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   322
    #[test]
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   323
    fn check_closest_row() {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   324
        let table = generate_table();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   325
        let pcard = PlayerCard{ player_id: 42, card: Card::new(42) };
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   326
        let closest = table.get_closest_row(&pcard);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   327
        assert_eq!( closest, Some(3) ); // index from 0
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   328
    }
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   329
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   330
    #[test]
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   331
    fn check_smallest_player_card() {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   332
        let mut table = generate_table();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   333
        
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   334
        let mut player_id = 1;
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   335
        vec![103, 8, 71, 93, 6].into_iter().for_each(|c| {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   336
            table.lay_player_card( Card::new(c), player_id);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   337
            player_id += 1;
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   338
        });
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   339
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   340
        let smallest = table.get_smallest_player_card();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   341
        assert_eq!( smallest, PlayerCard{ player_id: 5, card: Card::new(6) } );
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   342
    }
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   343
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   344
    fn generate_table() -> Table  {
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   345
        let mut row_cards = VecDeque::new();
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   346
        vec![5,7,10,33,70].into_iter().for_each(|c| row_cards.push_back( Card::new(c) ));
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   347
        let table = Table::new(row_cards);
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   348
        table
950660fddec0 Final version :-)
Peter Gervai <grin@grin.hu>
parents: 1
diff changeset
   349
    }
0
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   350
}
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   351
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   352
/*
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   353
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   354
- 1-104 lap, 
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   355
    - *5 - 2
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   356
    - *0 - 3
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   357
    - NN - 5
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   358
    - 55 - 7
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   359
- deck
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   360
- jatekosok; kezben tartott lapok; elvitt lapok; pontszamok; counter: elvitt sorok, okrok, total pont
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   361
-- keveres (keveresek szama)
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   362
-- osztas: mindenki 10 lap
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   363
-- start sorok: 5 kartya
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   364
- jatek (jatekok szama)
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   365
-- mindenki a felso lapot kiteszi
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   366
-- szamsorrendben felkerulnek, aki viszi, viszi
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   367
--- ha kisebb, akkor dontes
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   368
---- ha van legkevesebb, viszi
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   369
---- ha tobb min van, random valaszt
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   370
- osszesites
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   371
-- okrok, elvitt sorok
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   372
-- keveresek szama, jatekok szama, eltelt ido
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   373
- deck osszegyujtes
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   374
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   375
a95b84125269 Add repo.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
   376
*/