From c76c77e08d7f42dbd150949993aae3f82babfcca Mon Sep 17 00:00:00 2001 From: kbuffardi Date: Wed, 9 Sep 2015 11:16:22 -0700 Subject: [PATCH 01/40] Updates README.md for better formatting --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fd09ab5..e49aab7 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,14 @@ -# PigsGame -Pigs dice game +# Pigs dice game -This is a command-line implementation of Pig. The rules of the game as explaned on Wikipedia are:s +This is a command-line implementation of **Pig**. The rules of the game as explaned on Wikipedia are:s Each turn, a player repeatedly rolls a die until either a 1 is rolled or the player decides to "hold": -If the player rolls a 1, they score nothing and it becomes the next player's turn. -If the player rolls any other number, it is added to their turn total and the player's turn continues. -If a player chooses to "hold", their turn total is added to their score, and it becomes the next player's turn. -The first player to score 100 or more points wins. +> If the player rolls a 1, they score nothing and it becomes the next player's turn. +> If the player rolls any other number, it is added to their turn total and the player's turn continues. +> If a player chooses to "hold", their turn total is added to their score, and it > becomes the next player's turn. +> The first player to score 100 or more points wins. -From: https://en.wikipedia.org/wiki/Pig_(dice_game) +From [wikipedia](https://en.wikipedia.org/wiki/Pig_(dice_game)) This implementation is a single player game against a computer player. From e68cfa796f466cf9c5478ea4e6f12c2cde602163 Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 9 Sep 2015 12:30:20 -0700 Subject: [PATCH 02/40] Created Die class header and declared its members/methods --- die.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 die.h diff --git a/die.h b/die.h new file mode 100644 index 0000000..a56876e --- /dev/null +++ b/die.h @@ -0,0 +1,13 @@ +#ifndef DIE_H +#define DIE_H + +#define DIE_SIDES 6 + +class Die +{ + public: + int roll(); +}; + +#endif + From daa0f10c23c037d12d3f55ddc5849809711cc75a Mon Sep 17 00:00:00 2001 From: Eddie Date: Wed, 9 Sep 2015 12:30:52 -0700 Subject: [PATCH 03/40] Implemented Die::roll() --- die.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 die.cpp diff --git a/die.cpp b/die.cpp new file mode 100644 index 0000000..2d09697 --- /dev/null +++ b/die.cpp @@ -0,0 +1,8 @@ +#include // for rand() + +#include "die.h" + +int Die::roll() +{ + return (rand() % DIE_SIDES) + 1; +} From e2af2cfc1e6920d35b92b8a4756c89656cb89e11 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Wed, 9 Sep 2015 12:35:35 -0700 Subject: [PATCH 04/40] added structure Player class --- Player.cpp | 9 +++++++++ Player.h | 14 ++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 Player.cpp create mode 100644 Player.h diff --git a/Player.cpp b/Player.cpp new file mode 100644 index 0000000..96e8866 --- /dev/null +++ b/Player.cpp @@ -0,0 +1,9 @@ +#include +#include "Player.h" + +using namespace std; + +void Player::updateScore(int value) +{ + score += value; +} \ No newline at end of file diff --git a/Player.h b/Player.h new file mode 100644 index 0000000..48d96b1 --- /dev/null +++ b/Player.h @@ -0,0 +1,14 @@ +#ifndef PLAYER_H_INCLUDED +#define PLAYER_H_INCLUDED + +class Player +{ + public: + Jogador(); + ~Jogador(); + void updateScore(int value); + private: + int score; +}; + +#endif // PLAYER_H_INCLUDED \ No newline at end of file From 15a8c2bb7e7085590c7435258c1b5d9433863b1a Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Wed, 9 Sep 2015 12:35:35 -0700 Subject: [PATCH 05/40] added structure Player class --- Player.cpp | 9 +++++++++ Player.h | 14 ++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 Player.cpp create mode 100644 Player.h diff --git a/Player.cpp b/Player.cpp new file mode 100644 index 0000000..96e8866 --- /dev/null +++ b/Player.cpp @@ -0,0 +1,9 @@ +#include +#include "Player.h" + +using namespace std; + +void Player::updateScore(int value) +{ + score += value; +} \ No newline at end of file diff --git a/Player.h b/Player.h new file mode 100644 index 0000000..1bf1b96 --- /dev/null +++ b/Player.h @@ -0,0 +1,14 @@ +#ifndef PLAYER_H_INCLUDED +#define PLAYER_H_INCLUDED + +class Player +{ + public: + Player(); + ~Player(); + void updateScore(int value); + private: + int score; +}; + +#endif // PLAYER_H_INCLUDED \ No newline at end of file From d95136f055eb088593cb0666e1cc7edfb31f4395 Mon Sep 17 00:00:00 2001 From: JordanSalvagno Date: Wed, 9 Sep 2015 12:45:46 -0700 Subject: [PATCH 06/40] created outline for game class --- game.cpp | 33 +++++++++++++++++++++++++++++++++ game.h | 17 +++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 game.cpp create mode 100644 game.h diff --git a/game.cpp b/game.cpp new file mode 100644 index 0000000..00e21ef --- /dev/null +++ b/game.cpp @@ -0,0 +1,33 @@ +#include "player.h" +#include "dice.h" +#include +using namespace std; + +Game::Game() +{ +} + +Player* WhosTurn() +{ + return NULL; +} + +int GetCurrentPlayerScore() +{ + return 0; +} + +bool TurnChange() +{ + return false; +} + +int RollDice() +{ + return 0; +} + +bool AddPlayers(*Player) +{ + return false; +} diff --git a/game.h b/game.h new file mode 100644 index 0000000..80b3521 --- /dev/null +++ b/game.h @@ -0,0 +1,17 @@ +#include "player.h" +#include "dice.h" +#ifndef GAME_H +#define GAME_H + +class Game +{ + public: + Game(); + Player* WhosTurn(); + int GetPlayersScore(); + bool TurnChange; + int RollDice(); + bool AddPlayers(*Player); + private: + vector Players; +} From b64d00ef26c109b59e81c9cba425ee808627126a Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Wed, 9 Sep 2015 12:46:03 -0700 Subject: [PATCH 07/40] Update Player.h --- Player.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Player.h b/Player.h index 48d96b1..78023b6 100644 --- a/Player.h +++ b/Player.h @@ -4,11 +4,11 @@ class Player { public: - Jogador(); - ~Jogador(); + Player(); + ~Player(); void updateScore(int value); private: int score; }; -#endif // PLAYER_H_INCLUDED \ No newline at end of file +#endif // PLAYER_H_INCLUDED From a36af16d2e4d4785ccfe9b0ef570d273fba948de Mon Sep 17 00:00:00 2001 From: Eddie Date: Mon, 14 Sep 2015 11:31:22 -0700 Subject: [PATCH 08/40] Die constructor now seeds the rng. --- die.cpp | 8 +++++++- die.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/die.cpp b/die.cpp index 2d09697..cbe7d0d 100644 --- a/die.cpp +++ b/die.cpp @@ -1,7 +1,13 @@ -#include // for rand() +#include // for rand() +#include #include "die.h" +Die::Die() +{ + srand(time(NULL)); +} + int Die::roll() { return (rand() % DIE_SIDES) + 1; diff --git a/die.h b/die.h index a56876e..5e140a9 100644 --- a/die.h +++ b/die.h @@ -6,6 +6,7 @@ class Die { public: + Die(); int roll(); }; From f59fe543d6f1c1f4f8f2e0c73dce99292015de13 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Mon, 14 Sep 2015 11:37:36 -0700 Subject: [PATCH 09/40] added getScore --- Player.cpp | 10 +++++++--- Player.h | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Player.cpp b/Player.cpp index 96e8866..a033190 100644 --- a/Player.cpp +++ b/Player.cpp @@ -3,7 +3,11 @@ using namespace std; -void Player::updateScore(int value) +void Player::updateScore(int value) { - score += value; -} \ No newline at end of file + mScore += value; +} + +int Player::getScore() { + return mScore; +} diff --git a/Player.h b/Player.h index 1bf1b96..54d199c 100644 --- a/Player.h +++ b/Player.h @@ -5,10 +5,10 @@ class Player { public: Player(); - ~Player(); void updateScore(int value); + int getScore(); private: - int score; + int mScore; }; -#endif // PLAYER_H_INCLUDED \ No newline at end of file +#endif // PLAYER_H_INCLUDED From caddbdad3ea355b748276f78581832e0cea0382d Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Mon, 14 Sep 2015 11:45:11 -0700 Subject: [PATCH 10/40] Update Player.cpp Fix merge --- Player.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Player.cpp b/Player.cpp index ece036a..a033190 100644 --- a/Player.cpp +++ b/Player.cpp @@ -3,7 +3,6 @@ using namespace std; -<<<<<<< HEAD void Player::updateScore(int value) { mScore += value; @@ -12,9 +11,3 @@ void Player::updateScore(int value) int Player::getScore() { return mScore; } -======= -void Player::updateScore(int value) -{ - score += value; -} ->>>>>>> origin/player From 6bbdc08522db589631bb6a6779bc2cb11c4e02de Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Mon, 14 Sep 2015 18:27:21 -0700 Subject: [PATCH 11/40] Created CPU class, a derivative at player that has decision-making capabilities. --- CPU.cpp | 13 +++++++++++++ CPU.h | 10 ++++++++++ 2 files changed, 23 insertions(+) create mode 100644 CPU.cpp create mode 100644 CPU.h diff --git a/CPU.cpp b/CPU.cpp new file mode 100644 index 0000000..ebb5602 --- /dev/null +++ b/CPU.cpp @@ -0,0 +1,13 @@ +#include "CPU.h" + +bool CPU::determine_hold(int prev_roll, int cur_score, int roll_num) +{ + if (!cur_score || (prev_roll < 4 && cur_score < 6)) + { + IO.command(COM_ROLL); + } + else if ((cur_score > 9 && roll_num > 3) || roll_num > 4) + { + IO.command(COM_HOLD); + } +} diff --git a/CPU.h b/CPU.h new file mode 100644 index 0000000..29b9fce --- /dev/null +++ b/CPU.h @@ -0,0 +1,10 @@ +//Edward Brown +//PigsGame CPU Player class +#include "Player.h" + +//Note for later: implement a difficulty level +class CPU_Player: public Player +{ + private: + bool determine_hold(int prev_roll, int cur_score, int roll_num); +} From 9ed96297be473f928ae21059ca27820f0519c942 Mon Sep 17 00:00:00 2001 From: JordanSalvagno Date: Mon, 14 Sep 2015 19:11:21 -0700 Subject: [PATCH 12/40] created functions to handle what I believe the game class is doing, used object names from other files but am unsure of actual names --- game.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++++-------- game.h | 26 ++++++++++----- 2 files changed, 102 insertions(+), 20 deletions(-) diff --git a/game.cpp b/game.cpp index 00e21ef..5086a2e 100644 --- a/game.cpp +++ b/game.cpp @@ -1,33 +1,103 @@ -#include "player.h" -#include "dice.h" -#include +#include "game.h" using namespace std; Game::Game() { + int m_turn = 0; + int m_currentPlayer = 1; } -Player* WhosTurn() +//returns which players is currently playing +int whosTurn() { - return NULL; + if(m_number_of_players == 0) + { + return 0; + } + return m_current_player; } -int GetCurrentPlayerScore() +//gets what the current players score is +int getCurrentPlayerScore() +{ + if(m_current_player <= m_number_of_players) + { + return m_players[current_player-1]->getScore(); + } + if(m_current_player <= (m_number_of_comps + m_number_of_players)) + { + return m_comps[current_player - m_number_of_players - 1]->getScore(); + } +} + +//changes which player is taking their turn +bool turnChange() { - return 0; + m_turn = 0; + if(m_number_of_players == O) + { + return false; + } + if( m_current_player < (m_number_of_players + m_num_of_comps)) + { + m_current_player = m_current_player+1; + } + else + { + m_current_player = 1; + } + return true; } -bool TurnChange() +//takes a number as an argument then adds that number of human players to the game +void addPlayers(int n) { - return false; + m_number_of_Players = n; + for(i=0; i setScore(m_current_score); + return; + } + return m_comps[current_player - m_number_of_players - 1]->setScore(m_current_score); } + +//tells the AI player thats currently playing which roll their on, so it can decide wether to hold or roll, returns true if it wants to roll. +bool holdOrRoll() +{ + if(m_number_of_comps == 0) + { + return false; + } + return m_comps[current_player - m_number_of_players - 1]->roll(m_turn); +} + +//takes an number for what the dice was rolled. If number is 1, then player looses their turn score. Otherwise roll is added to total +int turnScore(int r) +{ + if(r == 1) + { + turnChange(); + return m_current_score = 0; + } + m_turn += 1; + return m_current_score += r; +} diff --git a/game.h b/game.h index 80b3521..02f487a 100644 --- a/game.h +++ b/game.h @@ -1,5 +1,4 @@ #include "player.h" -#include "dice.h" #ifndef GAME_H #define GAME_H @@ -7,11 +6,24 @@ class Game { public: Game(); - Player* WhosTurn(); - int GetPlayersScore(); - bool TurnChange; - int RollDice(); - bool AddPlayers(*Player); + int whosTurn(); + int getPlayersScore(); + bool turnChange(); + void addPlayers(int n); + void addComps(int n); + void setCurrentPlayerScore(int s); + bool holdOrRoll(); + void hold(); + int turnScore(int r); + private: - vector Players; + vector m_players; + vector m_comps; + int m_turn; + int m_current_score; + int m_number_of_players; + int m_numnber_of_comps; + int m_current_player; } +; +#endif From 518758dd32325958753790517ab21a0ba90e8242 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Mon, 14 Sep 2015 19:26:31 -0700 Subject: [PATCH 13/40] Minor changes: formating coding to CamelCase --- die.cpp | 2 +- die.h | 1 - game.cpp | 10 +++++----- game.h | 5 +++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/die.cpp b/die.cpp index cbe7d0d..c4acef6 100644 --- a/die.cpp +++ b/die.cpp @@ -1,7 +1,7 @@ #include // for rand() #include -#include "die.h" +#include "Die.h" Die::Die() { diff --git a/die.h b/die.h index 5e140a9..31a6227 100644 --- a/die.h +++ b/die.h @@ -11,4 +11,3 @@ class Die }; #endif - diff --git a/game.cpp b/game.cpp index 5086a2e..503616b 100644 --- a/game.cpp +++ b/game.cpp @@ -1,4 +1,4 @@ -#include "game.h" +#include "Game.h" using namespace std; Game::Game() @@ -19,8 +19,8 @@ int whosTurn() //gets what the current players score is int getCurrentPlayerScore() -{ - if(m_current_player <= m_number_of_players) +{ + if(m_current_player <= m_number_of_players) { return m_players[current_player-1]->getScore(); } @@ -72,7 +72,7 @@ void addComps(int n) //sends the current turn score to the player so they can add it to their total, then switches player who is taking their turn void hold() { - if(m_current_player <= m_number_of_players) + if(m_current_player <= m_number_of_players) { m_players[current_player-1]->setScore(m_current_score); return; @@ -100,4 +100,4 @@ int turnScore(int r) } m_turn += 1; return m_current_score += r; -} +} diff --git a/game.h b/game.h index 02f487a..439e7e3 100644 --- a/game.h +++ b/game.h @@ -1,7 +1,8 @@ -#include "player.h" #ifndef GAME_H #define GAME_H +#include "Player.h" + class Game { public: @@ -15,7 +16,7 @@ class Game bool holdOrRoll(); void hold(); int turnScore(int r); - + private: vector m_players; vector m_comps; From 89de580beba74a8b67130354231e00dedb16d066 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Mon, 14 Sep 2015 19:28:52 -0700 Subject: [PATCH 14/40] Added Header Guard --- CPU.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CPU.h b/CPU.h index 29b9fce..3f433a2 100644 --- a/CPU.h +++ b/CPU.h @@ -1,10 +1,14 @@ //Edward Brown //PigsGame CPU Player class +#ifndef PLAYER_H +#define PLAYER_H #include "Player.h" //Note for later: implement a difficulty level class CPU_Player: public Player { private: - bool determine_hold(int prev_roll, int cur_score, int roll_num); -} + bool determine_hold(int prev_roll, int cur_score, int roll_num); +}; + +#endif From d2debfa2f1d22bac3abde4d417065bde94e3747a Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Mon, 14 Sep 2015 19:33:07 -0700 Subject: [PATCH 15/40] Remaned class CPU -> CpuPlayer --- CPU.cpp => CpuPlayer.cpp | 4 ++-- CPU.h => CpuPlayer.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename CPU.cpp => CpuPlayer.cpp (64%) rename CPU.h => CpuPlayer.h (88%) diff --git a/CPU.cpp b/CpuPlayer.cpp similarity index 64% rename from CPU.cpp rename to CpuPlayer.cpp index ebb5602..85f4e86 100644 --- a/CPU.cpp +++ b/CpuPlayer.cpp @@ -1,6 +1,6 @@ -#include "CPU.h" +#include "CpuPlayer.h" -bool CPU::determine_hold(int prev_roll, int cur_score, int roll_num) +bool CpuPlayer::determine_hold(int prev_roll, int cur_score, int roll_num) { if (!cur_score || (prev_roll < 4 && cur_score < 6)) { diff --git a/CPU.h b/CpuPlayer.h similarity index 88% rename from CPU.h rename to CpuPlayer.h index 3f433a2..ac6b406 100644 --- a/CPU.h +++ b/CpuPlayer.h @@ -5,7 +5,7 @@ #include "Player.h" //Note for later: implement a difficulty level -class CPU_Player: public Player +class CpuPlayer: public Player { private: bool determine_hold(int prev_roll, int cur_score, int roll_num); From 5c7c31fd567a01bded57da767738f4e3fdce975d Mon Sep 17 00:00:00 2001 From: JordanSalvagno Date: Mon, 14 Sep 2015 19:35:12 -0700 Subject: [PATCH 16/40] updated Player and Cpu classes and functions --- game.cpp | 47 ++++++++++++++++++++++++++--------------------- game.h | 10 ++++++---- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/game.cpp b/game.cpp index 5086a2e..8b51e15 100644 --- a/game.cpp +++ b/game.cpp @@ -1,14 +1,17 @@ #include "game.h" +#include "Player.h" +#include "CPU.h" using namespace std; Game::Game() { - int m_turn = 0; - int m_currentPlayer = 1; + m_turn = 0; + m_pre_roll = 0; + m_currentPlayer = 1; } //returns which players is currently playing -int whosTurn() +int Game::whosTurn() { if(m_number_of_players == 0) { @@ -18,27 +21,27 @@ int whosTurn() } //gets what the current players score is -int getCurrentPlayerScore() +int Game::getCurrentPlayerScore() { if(m_current_player <= m_number_of_players) { - return m_players[current_player-1]->getScore(); + return m_players[m_current_player-1]->getScore(); } - if(m_current_player <= (m_number_of_comps + m_number_of_players)) + if(m_current_player <= (m_number_of_cpus + m_number_of_players)) { - return m_comps[current_player - m_number_of_players - 1]->getScore(); + return m_cpus[m_current_player - m_number_of_players - 1]->getScore(); } } //changes which player is taking their turn -bool turnChange() +bool Game::turnChange() { m_turn = 0; - if(m_number_of_players == O) + if(m_number_of_players == 0) { return false; } - if( m_current_player < (m_number_of_players + m_num_of_comps)) + if( m_current_player < (m_number_of_players + m_num_of_cpus)) { m_current_player = m_current_player+1; } @@ -50,7 +53,7 @@ bool turnChange() } //takes a number as an argument then adds that number of human players to the game -void addPlayers(int n) +void Game::addPlayers(int n) { m_number_of_Players = n; for(i=0; i setScore(m_current_score); + m_players[current_player-1]->updateScore(m_current_score); return; } - return m_comps[current_player - m_number_of_players - 1]->setScore(m_current_score); + return m_cpus[current_player - m_number_of_players - 1]->updateScore(m_current_score); } //tells the AI player thats currently playing which roll their on, so it can decide wether to hold or roll, returns true if it wants to roll. -bool holdOrRoll() +bool Game::holdOrRoll() { - if(m_number_of_comps == 0) + if(m_number_of_cpus == 0) { return false; } - return m_comps[current_player - m_number_of_players - 1]->roll(m_turn); + return m_cpus[current_player - m_number_of_players - 1]->determine_hold(m_pre_roll,m_current_score,m_turn); } //takes an number for what the dice was rolled. If number is 1, then player looses their turn score. Otherwise roll is added to total -int turnScore(int r) +int Game::turnScore(int r) { if(r == 1) { turnChange(); + m_pre_roll = 0; return m_current_score = 0; } m_turn += 1; + m_pre_roll = r; return m_current_score += r; } diff --git a/game.h b/game.h index 02f487a..d4db22a 100644 --- a/game.h +++ b/game.h @@ -1,6 +1,7 @@ -#include "player.h" #ifndef GAME_H #define GAME_H +#include "Player.h" +#include "CPU.h" class Game { @@ -10,7 +11,7 @@ class Game int getPlayersScore(); bool turnChange(); void addPlayers(int n); - void addComps(int n); + void addCpus(int n); void setCurrentPlayerScore(int s); bool holdOrRoll(); void hold(); @@ -18,11 +19,12 @@ class Game private: vector m_players; - vector m_comps; + vector m_cpus; int m_turn; + int m_pre_roll; int m_current_score; int m_number_of_players; - int m_numnber_of_comps; + int m_numnber_of_cpus; int m_current_player; } ; From cd541a790d4a535eb739019a7b65e38c2cddb925 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Mon, 14 Sep 2015 19:41:11 -0700 Subject: [PATCH 17/40] Remaned files, add library vector --- game.cpp => Game.cpp | 1 + game.h => Game.h | 2 ++ 2 files changed, 3 insertions(+) rename game.cpp => Game.cpp (99%) rename game.h => Game.h (93%) diff --git a/game.cpp b/Game.cpp similarity index 99% rename from game.cpp rename to Game.cpp index 503616b..0ad9842 100644 --- a/game.cpp +++ b/Game.cpp @@ -1,4 +1,5 @@ #include "Game.h" +#include using namespace std; Game::Game() diff --git a/game.h b/Game.h similarity index 93% rename from game.h rename to Game.h index 439e7e3..c704037 100644 --- a/game.h +++ b/Game.h @@ -1,5 +1,7 @@ #ifndef GAME_H #define GAME_H +#include +using namespace std; #include "Player.h" From bf9b7de3552c4dc07b9584825d4c14a1fecb40bb Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Mon, 14 Sep 2015 19:48:28 -0700 Subject: [PATCH 18/40] Remaned CPU_Player -> CpuPlayer --- Game.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Game.cpp b/Game.cpp index c0e1aad..068ca1f 100644 --- a/Game.cpp +++ b/Game.cpp @@ -69,7 +69,7 @@ void Game::addCPUs(int n) m_number_of_cpus = n; for(i=0; i Date: Mon, 14 Sep 2015 19:57:53 -0700 Subject: [PATCH 19/40] Fixed some typos --- Game.cpp | 22 +++++++++++----------- Game.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Game.cpp b/Game.cpp index 068ca1f..ecbb7d7 100644 --- a/Game.cpp +++ b/Game.cpp @@ -8,7 +8,7 @@ Game::Game() { m_turn = 0; m_pre_roll = 0; - m_currentPlayer = 1; + m_current_player = 1; } //returns which players is currently playing @@ -42,7 +42,7 @@ bool Game::turnChange() { return false; } - if( m_current_player < (m_number_of_players + m_num_of_cpus)) + if( m_current_player < (m_number_of_players + m_number_of_cpus)) { m_current_player = m_current_player+1; } @@ -56,20 +56,20 @@ bool Game::turnChange() //takes a number as an argument then adds that number of human players to the game void Game::addPlayers(int n) { - m_number_of_Players = n; - for(i=0; i updateScore(m_current_score); + m_players[m_current_player-1]->updateScore(m_current_score); return; } - return m_cpus[current_player - m_number_of_players - 1]->updateScore(m_current_score); + return m_cpus[m_current_player - m_number_of_players - 1]->updateScore(m_current_score); } //tells the AI player thats currently playing which roll their on, so it can decide wether to hold or roll, returns true if it wants to roll. @@ -91,7 +91,7 @@ bool Game::holdOrRoll() { return false; } - return m_cpus[current_player - m_number_of_players - 1]->determine_hold(m_pre_roll,m_current_score,m_turn); + return m_cpus[m_current_player - m_number_of_players - 1]->determine_hold(m_pre_roll,m_current_score,m_turn); } //takes an number for what the dice was rolled. If number is 1, then player looses their turn score. Otherwise roll is added to total diff --git a/Game.h b/Game.h index 987c642..a4d0e10 100644 --- a/Game.h +++ b/Game.h @@ -28,7 +28,7 @@ class Game int m_pre_roll; int m_current_score; int m_number_of_players; - int m_numnber_of_cpus; + int m_number_of_cpus; int m_current_player; }; From ab1e3061347c049383c42f7bb1953a57e6b6375c Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Mon, 14 Sep 2015 19:59:04 -0700 Subject: [PATCH 20/40] Added undeclared method in .h file --- Game.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Game.h b/Game.h index a4d0e10..d3a8451 100644 --- a/Game.h +++ b/Game.h @@ -16,6 +16,7 @@ class Game bool turnChange(); void addPlayers(int n); void addCpus(int n); + int getCurrentPlayerScore(); void setCurrentPlayerScore(int s); bool holdOrRoll(); void hold(); From f480b6da94c4b01ad60bf65af4fa135ac2247578 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Mon, 14 Sep 2015 20:04:11 -0700 Subject: [PATCH 21/40] Fixed undefined class --- Game.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Game.h b/Game.h index d3a8451..955943a 100644 --- a/Game.h +++ b/Game.h @@ -24,7 +24,7 @@ class Game private: vector m_players; - vector m_cpus; + vector m_cpus; int m_turn; int m_pre_roll; int m_current_score; From 8a73f66fcc03284fb38b77a27a4bcc4d9d9fa5f8 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Mon, 14 Sep 2015 20:04:55 -0700 Subject: [PATCH 22/40] Made determine_hold public as it is required in Game --- CpuPlayer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CpuPlayer.h b/CpuPlayer.h index ac6b406..45f6f47 100644 --- a/CpuPlayer.h +++ b/CpuPlayer.h @@ -7,7 +7,7 @@ //Note for later: implement a difficulty level class CpuPlayer: public Player { - private: +public: bool determine_hold(int prev_roll, int cur_score, int roll_num); }; From a54587c6e236cb7de92b37e6a07ca9e09a7baee4 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Mon, 14 Sep 2015 20:11:10 -0700 Subject: [PATCH 23/40] Rename die.cpp to Die.cpp --- die.cpp => Die.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename die.cpp => Die.cpp (100%) diff --git a/die.cpp b/Die.cpp similarity index 100% rename from die.cpp rename to Die.cpp From adfbe51019277709b4c100029119a2a3b07bdc0b Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Mon, 14 Sep 2015 20:11:26 -0700 Subject: [PATCH 24/40] Rename die.h to Die.h --- die.h => Die.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename die.h => Die.h (100%) diff --git a/die.h b/Die.h similarity index 100% rename from die.h rename to Die.h From 1dd13622995cd9e6e1e2a3198176ee5ed3cf4398 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 16:22:59 -0700 Subject: [PATCH 25/40] Created main file/function --- main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 main.cpp diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e825bbf --- /dev/null +++ b/main.cpp @@ -0,0 +1,10 @@ +#incldue "Game.h" + +int main() +{ + Game game; + + game.start(); + + return 0; +} From 44f09636eef07dea7a6178985b759b4e06974958 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 16:27:04 -0700 Subject: [PATCH 26/40] Created prototype method Start in Game --- Game.cpp | 5 +++++ Game.h | 1 + 2 files changed, 6 insertions(+) diff --git a/Game.cpp b/Game.cpp index ecbb7d7..7425572 100644 --- a/Game.cpp +++ b/Game.cpp @@ -107,3 +107,8 @@ int Game::turnScore(int r) m_pre_roll = r; return m_current_score += r; } + +void Game::start() +{ + +} diff --git a/Game.h b/Game.h index 955943a..5ba9b60 100644 --- a/Game.h +++ b/Game.h @@ -21,6 +21,7 @@ class Game bool holdOrRoll(); void hold(); int turnScore(int r); + void start(); private: vector m_players; From 88bd4e8c83371f0fc81be60f28547198e032615f Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 16:30:19 -0700 Subject: [PATCH 27/40] CpuPlayer is a Player, so that we just need one vector of players --- Game.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Game.h b/Game.h index 5ba9b60..9d4a171 100644 --- a/Game.h +++ b/Game.h @@ -25,7 +25,7 @@ class Game private: vector m_players; - vector m_cpus; + // vector m_cpus; int m_turn; int m_pre_roll; int m_current_score; From 4fac8e721199f301efc03c5f6b4908e45acf6f86 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 16:32:17 -0700 Subject: [PATCH 28/40] Fixed typo --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index e825bbf..014ce89 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,4 @@ -#incldue "Game.h" +#include "Game.h" int main() { From 39e6037aa27272a0384a358bcd5f0ce911beb4df Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 16:36:06 -0700 Subject: [PATCH 29/40] Now adding CpuPlayer to vector of players --- Game.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Game.cpp b/Game.cpp index 7425572..07a60b1 100644 --- a/Game.cpp +++ b/Game.cpp @@ -67,9 +67,9 @@ void Game::addPlayers(int n) void Game::addCpus(int n) { m_number_of_cpus = n; - for(int i=0; i Date: Tue, 15 Sep 2015 16:39:58 -0700 Subject: [PATCH 30/40] Fixed getCurrentPlayerScore to use only one vector --- Game.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Game.cpp b/Game.cpp index 07a60b1..102e4cb 100644 --- a/Game.cpp +++ b/Game.cpp @@ -24,14 +24,7 @@ int Game::whosTurn() //gets what the current players score is int Game::getCurrentPlayerScore() { - if(m_current_player <= m_number_of_players) - { return m_players[m_current_player-1]->getScore(); - } - if(m_current_player <= (m_number_of_cpus + m_number_of_players)) - { - return m_cpus[m_current_player - m_number_of_players - 1]->getScore(); - } } //changes which player is taking their turn From 924cdb9fccc9ab974ac9080ca387ba7df2fcf2f5 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 16:41:27 -0700 Subject: [PATCH 31/40] We don't a function to do that --- Game.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/Game.cpp b/Game.cpp index 102e4cb..288bc1f 100644 --- a/Game.cpp +++ b/Game.cpp @@ -27,25 +27,6 @@ int Game::getCurrentPlayerScore() return m_players[m_current_player-1]->getScore(); } -//changes which player is taking their turn -bool Game::turnChange() -{ - m_turn = 0; - if(m_number_of_players == 0) - { - return false; - } - if( m_current_player < (m_number_of_players + m_number_of_cpus)) - { - m_current_player = m_current_player+1; - } - else - { - m_current_player = 1; - } - return true; -} - //takes a number as an argument then adds that number of human players to the game void Game::addPlayers(int n) { From 56bd1c2a1dbfb9a28573c58ee1d5746d3bb9bef1 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 16:42:20 -0700 Subject: [PATCH 32/40] Don't need m_cpus anymore --- Game.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Game.cpp b/Game.cpp index 288bc1f..0810de2 100644 --- a/Game.cpp +++ b/Game.cpp @@ -55,7 +55,6 @@ void Game::hold() m_players[m_current_player-1]->updateScore(m_current_score); return; } - return m_cpus[m_current_player - m_number_of_players - 1]->updateScore(m_current_score); } //tells the AI player thats currently playing which roll their on, so it can decide wether to hold or roll, returns true if it wants to roll. From 19fc31818dcdfed47d50070c116c5479e0b4628f Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 16:48:16 -0700 Subject: [PATCH 33/40] Added Turn method to player --- CpuPlayer.cpp | 5 +++++ CpuPlayer.h | 1 + Player.cpp | 6 ++++++ Player.h | 1 + 4 files changed, 13 insertions(+) diff --git a/CpuPlayer.cpp b/CpuPlayer.cpp index 85f4e86..8c2c34f 100644 --- a/CpuPlayer.cpp +++ b/CpuPlayer.cpp @@ -11,3 +11,8 @@ bool CpuPlayer::determine_hold(int prev_roll, int cur_score, int roll_num) IO.command(COM_HOLD); } } + +bool turn() +{ + return true; +} diff --git a/CpuPlayer.h b/CpuPlayer.h index 45f6f47..37b34bb 100644 --- a/CpuPlayer.h +++ b/CpuPlayer.h @@ -9,6 +9,7 @@ class CpuPlayer: public Player { public: bool determine_hold(int prev_roll, int cur_score, int roll_num); + bool turn(); }; #endif diff --git a/Player.cpp b/Player.cpp index a033190..6103556 100644 --- a/Player.cpp +++ b/Player.cpp @@ -3,6 +3,12 @@ using namespace std; +bool turn() +{ + return true; +} + + void Player::updateScore(int value) { mScore += value; diff --git a/Player.h b/Player.h index 54d199c..b61cebb 100644 --- a/Player.h +++ b/Player.h @@ -7,6 +7,7 @@ class Player Player(); void updateScore(int value); int getScore(); + virtual bool turn(); private: int mScore; }; From 0c049556712583fe532298368afc1a9f9bfcea46 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 17:06:07 -0700 Subject: [PATCH 34/40] Pushing/Merging Thomas Carrel branch --- Io.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Io.h | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 Io.cpp create mode 100644 Io.h diff --git a/Io.cpp b/Io.cpp new file mode 100644 index 0000000..777b947 --- /dev/null +++ b/Io.cpp @@ -0,0 +1,79 @@ +//Thomas Russel Carrel +#include"io.h" + +//////////////////////////////////////////////////////////////////////////////// +// +// Tracks the number of Io objects created, prevents the creation of more than +// one. +// +//////////////////////////////////////////////////////////////////////////////// +Io::io_num = 0; + +//////////////////////////////////////////////////////////////////////////////// +//PRIVATE ctor, prevents creation of Io class by any class other than game. +//////////////////////////////////////////////////////////////////////////////// +// +// Io( Game* g ); +// +// +//////////////////////////////////////////////////////////////////////////////// +Io::Io() +{ + if( io_num > 0 ) //Prevent creation of more than one io object. + { + return; + } + + io_num++; + + //########################################################################### + // Code for player's initial setup choices might go here. Things like + // difficulty and number of sides on the die. + //########################################################################### +} + +int Io::turn(Player* player, int player_num) +{ + unsigned char command = 'X'; + + while ( command != 'r' && command != 'h' ) + { + cout << "\nPlayer number " << player_num << ":\n\t(R)oll or (H)old? "; + + switch( player->get_command() ) //Human player should return COM_NOT_CPU + { // This makes the cpu look like it's entering commands as well. + case COM_HOLD: + cout << "h" << endl; + command = 'h'; + break; + case COM_ROLL: + cout << "r" << endl; + command = 'r'; + break; + case COM_NOT_CPU: + //fallthrough. + default: + cin >> command; + } + + if( 'A' >= command && command <= 'Z' ) //Switch to lowercase, if necessary. + { + command += 32; + } + } + + if( command = 'h' ) + { + return HOLD; + } + + Die die; // DIIIIIEEEEEEEEEEE!!!!!!!!!!!! + + return die.roll(); // Roll the die and return its result. +} + +void Io::winner(int player_num) +{ + cout << "Player number " << player_num + << " has reached 100 points for the win!"; +} diff --git a/Io.h b/Io.h new file mode 100644 index 0000000..ec1159b --- /dev/null +++ b/Io.h @@ -0,0 +1,45 @@ +// Thomas Russel Carrel +// +// io.h +// +// Class handles input from the player and sends it to the game's main class. +// The game's main class performs its own actions and returns appropriate +// output to the screen + +#ifndef _Io_H +#define _Io_H + +#include + +using std::cout; +using std::cin; +using std::endl; + +const int HOLD = -1; + +enum Commands +{ + COM_NOT_CPU, + COM_HOLD, + COM_ROLL +}; + +class Io +{ + public: + + // Returns HOLD if the player decides to hold, otherwise, returns the + //value from the die. + int turn( Player*, int ); + + void winner(int); // Displays a victory message. + + friend class Game; + private: + Io(); // Constructor can only be called by the game class. Prevents other + // classes from creating their own instance of this class. + + static int io_num; // To prevent multiple instances. +} + +#endif From c6a884c67dba58f588ad16f0a0c257e6258612d2 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 17:31:51 -0700 Subject: [PATCH 35/40] Get rid of compiler errors by brutal force --- CpuPlayer.cpp | 23 ++++++++++++----------- CpuPlayer.h | 2 +- Game.cpp | 8 +++++--- Game.h | 2 +- Io.cpp | 34 ++++++++++++++++++---------------- Io.h | 20 +++++++++----------- Player.cpp | 5 ++--- Player.h | 1 - 8 files changed, 48 insertions(+), 47 deletions(-) diff --git a/CpuPlayer.cpp b/CpuPlayer.cpp index 8c2c34f..fa50c1f 100644 --- a/CpuPlayer.cpp +++ b/CpuPlayer.cpp @@ -1,18 +1,19 @@ #include "CpuPlayer.h" -bool CpuPlayer::determine_hold(int prev_roll, int cur_score, int roll_num) +CpuPlayer::CpuPlayer() { - if (!cur_score || (prev_roll < 4 && cur_score < 6)) - { - IO.command(COM_ROLL); - } - else if ((cur_score > 9 && roll_num > 3) || roll_num > 4) - { - IO.command(COM_HOLD); - } + } -bool turn() +bool CpuPlayer::determine_hold(int prev_roll, int cur_score, int roll_num) { - return true; + // if (!cur_score || (prev_roll < 4 && cur_score < 6)) + // { + // IO.command(COM_ROLL); + // } + // else if ((cur_score > 9 && roll_num > 3) || roll_num > 4) + // { + // IO.command(COM_HOLD); + // } + return false; } diff --git a/CpuPlayer.h b/CpuPlayer.h index 37b34bb..54b378d 100644 --- a/CpuPlayer.h +++ b/CpuPlayer.h @@ -8,8 +8,8 @@ class CpuPlayer: public Player { public: + CpuPlayer(); bool determine_hold(int prev_roll, int cur_score, int roll_num); - bool turn(); }; #endif diff --git a/Game.cpp b/Game.cpp index 0810de2..8ef9783 100644 --- a/Game.cpp +++ b/Game.cpp @@ -2,6 +2,7 @@ #include "Game.h" #include "Player.h" #include "CpuPlayer.h" +#include "Io.h" using namespace std; Game::Game() @@ -64,7 +65,8 @@ bool Game::holdOrRoll() { return false; } - return m_cpus[m_current_player - m_number_of_players - 1]->determine_hold(m_pre_roll,m_current_score,m_turn); + return true; + // return m_cpus[m_current_player - m_number_of_players - 1]->determine_hold(m_pre_roll,m_current_score,m_turn); } //takes an number for what the dice was rolled. If number is 1, then player looses their turn score. Otherwise roll is added to total @@ -72,7 +74,7 @@ int Game::turnScore(int r) { if(r == 1) { - turnChange(); + // turnChange(); m_pre_roll = 0; return m_current_score = 0; } @@ -83,5 +85,5 @@ int Game::turnScore(int r) void Game::start() { - + Io io; } diff --git a/Game.h b/Game.h index 9d4a171..c559001 100644 --- a/Game.h +++ b/Game.h @@ -13,7 +13,7 @@ class Game Game(); int whosTurn(); int getPlayersScore(); - bool turnChange(); + // bool turnChange(); void addPlayers(int n); void addCpus(int n); int getCurrentPlayerScore(); diff --git a/Io.cpp b/Io.cpp index 777b947..93792cd 100644 --- a/Io.cpp +++ b/Io.cpp @@ -1,13 +1,15 @@ //Thomas Russel Carrel -#include"io.h" +#include "Io.h" +#include +using namespace std; //////////////////////////////////////////////////////////////////////////////// -// +// // Tracks the number of Io objects created, prevents the creation of more than // one. // //////////////////////////////////////////////////////////////////////////////// -Io::io_num = 0; +// Io::int io_num = 0; //////////////////////////////////////////////////////////////////////////////// //PRIVATE ctor, prevents creation of Io class by any class other than game. @@ -15,16 +17,16 @@ Io::io_num = 0; // // Io( Game* g ); // -// +// //////////////////////////////////////////////////////////////////////////////// -Io::Io() +Io::Io() { - if( io_num > 0 ) //Prevent creation of more than one io object. - { - return; - } - - io_num++; + // if( io_num > 0 ) //Prevent creation of more than one io object. + // { + // return; + // } + // + // io_num++; //########################################################################### // Code for player's initial setup choices might go here. Things like @@ -40,7 +42,7 @@ int Io::turn(Player* player, int player_num) { cout << "\nPlayer number " << player_num << ":\n\t(R)oll or (H)old? "; - switch( player->get_command() ) //Human player should return COM_NOT_CPU + switch( COM_HOLD /*player->get_command() */) //Human player should return COM_NOT_CPU { // This makes the cpu look like it's entering commands as well. case COM_HOLD: cout << "h" << endl; @@ -60,9 +62,9 @@ int Io::turn(Player* player, int player_num) { command += 32; } - } + } - if( command = 'h' ) + if( command == 'h' ) { return HOLD; } @@ -73,7 +75,7 @@ int Io::turn(Player* player, int player_num) } void Io::winner(int player_num) -{ - cout << "Player number " << player_num +{ + cout << "Player number " << player_num << " has reached 100 points for the win!"; } diff --git a/Io.h b/Io.h index ec1159b..1c4b82e 100644 --- a/Io.h +++ b/Io.h @@ -9,24 +9,22 @@ #ifndef _Io_H #define _Io_H -#include - -using std::cout; -using std::cin; -using std::endl; +#include +#include "Player.h" +#include "Die.h" const int HOLD = -1; -enum Commands +enum Commands { COM_NOT_CPU, COM_HOLD, - COM_ROLL + COM_ROLL }; class Io { - public: + public: // Returns HOLD if the player decides to hold, otherwise, returns the //value from the die. @@ -38,8 +36,8 @@ class Io private: Io(); // Constructor can only be called by the game class. Prevents other // classes from creating their own instance of this class. - - static int io_num; // To prevent multiple instances. -} + + // static int io_num = 0; // To prevent multiple instances. +}; #endif diff --git a/Player.cpp b/Player.cpp index 6103556..23df67d 100644 --- a/Player.cpp +++ b/Player.cpp @@ -3,12 +3,11 @@ using namespace std; -bool turn() +Player::Player() { - return true; + mScore = 0; } - void Player::updateScore(int value) { mScore += value; diff --git a/Player.h b/Player.h index b61cebb..54d199c 100644 --- a/Player.h +++ b/Player.h @@ -7,7 +7,6 @@ class Player Player(); void updateScore(int value); int getScore(); - virtual bool turn(); private: int mScore; }; From 23c88014f2358426f4b97623887b3220cc2b3dc5 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 18:52:49 -0700 Subject: [PATCH 36/40] Made roll static --- Die.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Die.h b/Die.h index 31a6227..e5d48ee 100644 --- a/Die.h +++ b/Die.h @@ -7,7 +7,7 @@ class Die { public: Die(); - int roll(); + static int roll(); }; #endif From 9404cb50082df3b456a24c8f9dfa3c68150cb763 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 18:55:17 -0700 Subject: [PATCH 37/40] Basic IA to decide to hold or die and name method added --- CpuPlayer.cpp | 18 ++++++++++++++++++ CpuPlayer.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/CpuPlayer.cpp b/CpuPlayer.cpp index fa50c1f..853eec3 100644 --- a/CpuPlayer.cpp +++ b/CpuPlayer.cpp @@ -1,4 +1,6 @@ #include "CpuPlayer.h" +#include +#include CpuPlayer::CpuPlayer() { @@ -17,3 +19,19 @@ bool CpuPlayer::determine_hold(int prev_roll, int cur_score, int roll_num) // } return false; } + +int CpuPlayer::get_command(int cur_score) +{ + // int cur_score = 0;// game->getCurrentPlayerScore(); + std::this_thread::sleep_for(std::chrono::seconds(1)); // thinking + + if (cur_score < 20) { + return COM_ROLL; + } + return COM_HOLD; +} + +std::string CpuPlayer::name() +{ + return "CPU"; +} diff --git a/CpuPlayer.h b/CpuPlayer.h index 54b378d..2257b5e 100644 --- a/CpuPlayer.h +++ b/CpuPlayer.h @@ -3,6 +3,8 @@ #ifndef PLAYER_H #define PLAYER_H #include "Player.h" +#include "Io.h" +#include //Note for later: implement a difficulty level class CpuPlayer: public Player @@ -10,6 +12,8 @@ class CpuPlayer: public Player public: CpuPlayer(); bool determine_hold(int prev_roll, int cur_score, int roll_num); + virtual int get_command(int); + virtual std::string name(); }; #endif From ad64051b17729328c6ff6f229a48a1553e853025 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 18:56:04 -0700 Subject: [PATCH 38/40] Added default get_comand and name --- Player.cpp | 8 ++++++++ Player.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/Player.cpp b/Player.cpp index 23df67d..5d2c05c 100644 --- a/Player.cpp +++ b/Player.cpp @@ -8,6 +8,10 @@ Player::Player() mScore = 0; } +int Player::get_command(int r) { + return -1; // human player +} + void Player::updateScore(int value) { mScore += value; @@ -16,3 +20,7 @@ void Player::updateScore(int value) int Player::getScore() { return mScore; } + +std::string Player::name() { + return "Player"; +} diff --git a/Player.h b/Player.h index 54d199c..c5adcf9 100644 --- a/Player.h +++ b/Player.h @@ -1,5 +1,6 @@ #ifndef PLAYER_H_INCLUDED #define PLAYER_H_INCLUDED +#include class Player { @@ -7,6 +8,8 @@ class Player Player(); void updateScore(int value); int getScore(); + virtual int get_command(int); + virtual std::string name(); private: int mScore; }; From dfdd97416455522097034eadd3366e337189f850 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 18:57:27 -0700 Subject: [PATCH 39/40] Defined start method --- Game.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++-------------- Game.h | 2 ++ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/Game.cpp b/Game.cpp index 8ef9783..667be33 100644 --- a/Game.cpp +++ b/Game.cpp @@ -3,13 +3,18 @@ #include "Player.h" #include "CpuPlayer.h" #include "Io.h" +#include + using namespace std; Game::Game() { m_turn = 0; - m_pre_roll = 0; - m_current_player = 1; + // m_pre_roll = 0; + // m_current_player = 1; + + addPlayers(1); + addCpus(1); } //returns which players is currently playing @@ -25,7 +30,7 @@ int Game::whosTurn() //gets what the current players score is int Game::getCurrentPlayerScore() { - return m_players[m_current_player-1]->getScore(); + return m_players[m_current_player]->getScore(); } //takes a number as an argument then adds that number of human players to the game @@ -51,11 +56,11 @@ void Game::addCpus(int n) //sends the current turn score to the player so they can add it to their total, then switches player who is taking their turn void Game::hold() { - if(m_current_player <= m_number_of_players) - { - m_players[m_current_player-1]->updateScore(m_current_score); - return; - } + // if(m_current_player <= m_number_of_players) + // { + m_players[m_current_player]->updateScore(m_current_score); + // return; + // } } //tells the AI player thats currently playing which roll their on, so it can decide wether to hold or roll, returns true if it wants to roll. @@ -72,12 +77,12 @@ bool Game::holdOrRoll() //takes an number for what the dice was rolled. If number is 1, then player looses their turn score. Otherwise roll is added to total int Game::turnScore(int r) { - if(r == 1) - { - // turnChange(); - m_pre_roll = 0; - return m_current_score = 0; - } + // if(r == 1) + // { + // // turnChange(); + // m_pre_roll = 0; + // return m_current_score = 0; + // } m_turn += 1; m_pre_roll = r; return m_current_score += r; @@ -85,5 +90,30 @@ int Game::turnScore(int r) void Game::start() { + int n = 0; Io io; + + while(true) { + + m_current_player = n % 2; // change back and forth players (2) + while (io.turn(m_players[m_current_player], m_current_player, m_current_score) != HOLD) + { + int turn = Die::roll(); + if (turn == 1) { + cout << "\t\t\t =( You rolled 1. Nothing scored!" << endl; + m_current_score = 0; + break; + } + cout << "\t\t\tYou rolled: " << turn; + turnScore(turn); + } + hold(); + + if (m_players[m_current_player]->getScore() >= 100) { + io.winner(m_current_player); + return; + } + + n++; + } } diff --git a/Game.h b/Game.h index c559001..1f508a2 100644 --- a/Game.h +++ b/Game.h @@ -6,6 +6,8 @@ using namespace std; #include "Player.h" #include "CpuPlayer.h" +#include "Game.h" +#include "Io.h" class Game { From c406fba768a9b616ebbcf9b7888316c3e9d19995 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Date: Tue, 15 Sep 2015 18:58:38 -0700 Subject: [PATCH 40/40] Basicaly remove Die from IO and get_command(cur_score) --- Io.cpp | 12 +++++++----- Io.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Io.cpp b/Io.cpp index 93792cd..cd1844b 100644 --- a/Io.cpp +++ b/Io.cpp @@ -34,15 +34,17 @@ Io::Io() //########################################################################### } -int Io::turn(Player* player, int player_num) +int Io::turn(Player* player, int player_num, int cur_score) { unsigned char command = 'X'; while ( command != 'r' && command != 'h' ) { - cout << "\nPlayer number " << player_num << ":\n\t(R)oll or (H)old? "; + cout << "\t\t\tTotal Score: " << player->getScore() << endl; + cout << "\t\t\tTurn Score: " << cur_score << endl; + cout << player->name() << ":\n\t(R)oll or (H)old? "; - switch( COM_HOLD /*player->get_command() */) //Human player should return COM_NOT_CPU + switch( player->get_command(cur_score) ) //Human player should return COM_NOT_CPU { // This makes the cpu look like it's entering commands as well. case COM_HOLD: cout << "h" << endl; @@ -69,9 +71,9 @@ int Io::turn(Player* player, int player_num) return HOLD; } - Die die; // DIIIIIEEEEEEEEEEE!!!!!!!!!!!! + // Die die; // DIIIIIEEEEEEEEEEE!!!!!!!!!!!! - return die.roll(); // Roll the die and return its result. + return COM_ROLL; //die.roll(); // Roll the die and return its result. } void Io::winner(int player_num) diff --git a/Io.h b/Io.h index 1c4b82e..3ea065d 100644 --- a/Io.h +++ b/Io.h @@ -28,7 +28,7 @@ class Io // Returns HOLD if the player decides to hold, otherwise, returns the //value from the die. - int turn( Player*, int ); + int turn( Player*, int player_num, int score); void winner(int); // Displays a victory message.