summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/set.cpp5
-rw-r--r--common/set.h21
-rw-r--r--common/state.h42
-rw-r--r--server/game.cpp3
-rw-r--r--server/gamevariant.h20
-rw-r--r--server/standard.cpp501
-rw-r--r--server/standard.h36
7 files changed, 0 insertions, 628 deletions
diff --git a/common/set.cpp b/common/set.cpp
deleted file mode 100644
index ce44f02..0000000
--- a/common/set.cpp
+++ /dev/null
@@ -1,5 +0,0 @@
-#include "set.h"
-
-void Set::add_tile(Tile tile) {
- container.push_back(tile);
-}
diff --git a/common/set.h b/common/set.h
deleted file mode 100644
index b7cceaa..0000000
--- a/common/set.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef CHI_H
-#define CHI_H
-
-#include "tile.h"
-
-//! Contains a set of tiles
-class Set : public Tile {
- private:
- Tiles container;
-
- public:
- Set(){};
- virtual ~Set(){};
-
- //! Add a tile to the set
- //! \param tile The tile that should be added to the set
- void add_tile(Tile tile);
-};
-
-
-#endif // CHI_H
diff --git a/common/state.h b/common/state.h
deleted file mode 100644
index 96f171f..0000000
--- a/common/state.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#ifndef STATE_H
-#define STATE_H
-
-#include <boost/shared_ptr.hpp>
-
-#include "tile.h"
-#include "action.h"
-
-class State {
- public:
- typedef boost::shared_ptr<State> p;
-
- struct Player {
- //! Concealed tiles in hand.
- Tiles hand;
- //! Open tiles in hand.
- Tiles open;
- //! Discarded tiles.
- Tiles pond;
-
- template<class Archive>
- void serialize(Archive & ar, const unsigned int version) {
- ar & hand;
- ar & open;
- ar & pond;
- }
- };
-
- //! State of players.
- Player players[4];
-
- //! Possible actions.
- Actions possible_actions;
-
- template<class Archive>
- void serialize(Archive & ar, const unsigned int version) {
- ar & players;
- ar & possible_actions;
- }
-};
-
-#endif \ No newline at end of file
diff --git a/server/game.cpp b/server/game.cpp
index 26d0ce4..56885c3 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -10,9 +10,6 @@
#include <ctime>
#endif
-#include "../common/set.h"
-
-
Game::p Game::create(Client::p player_1, Client::p player_2, Client::p player_3, Client::p player_4) {
Game::p p(new Game(player_1, player_2, player_3, player_4));
p->start();
diff --git a/server/gamevariant.h b/server/gamevariant.h
deleted file mode 100644
index 6fb2c56..0000000
--- a/server/gamevariant.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef GAMEVARIANT_H
-#define GAMEVARIANT_H
-
-#include "../common/state.h"
-#include "../common/action.h"
-
-class GameVariant {
- private:
- State game_state;
-
- public:
- virtual ~GameVariant(){};
-
- virtual void round_start() = 0;
- virtual State& round_update() = 0;
- virtual bool round_action(Action action) = 0;
-};
-
-#endif // GAMEVARIANT_H
-
diff --git a/server/standard.cpp b/server/standard.cpp
deleted file mode 100644
index a35a358..0000000
--- a/server/standard.cpp
+++ /dev/null
@@ -1,501 +0,0 @@
-#include "standard.h"
-
-#include <algorithm>
-
-#ifdef DEBUG
-#include <ctime>
-#include <iostream>
-#endif
-
-using namespace RuleSet;
-bool MyDataSortPredicate(const Tile& d1, const Tile& d2) {
- return d1.type < d2.type;
-}
-
-void Standard::round_start() {
-
- // Sett opp runden sin state
- //game_state = make_shared<State>();
-
- // Simulates drawing 4, 4 ,4 for each player
- for (int i = 0; i < 3; i++) {
- for (int player_num = 0; player_num < 4; player_num++) {
- for (int y = 0; y < 4; y++) {
- game_state.players[player_num].hand.push_back(wall.take_one());
- }
- }
- }
-
- // Simulates the second part of drawing with only 1 tile
- for (int player_num = 0; player_num < 4; player_num++) {
- game_state.players[player_num].hand.push_back(wall.take_one());
- }
-
- std::sort(game_state.players[0].hand.begin(),game_state.players[0].hand.end(), MyDataSortPredicate);
- std::sort(game_state.players[1].hand.begin(),game_state.players[1].hand.end(), MyDataSortPredicate);
- std::sort(game_state.players[2].hand.begin(),game_state.players[2].hand.end(), MyDataSortPredicate);
- std::sort(game_state.players[3].hand.begin(),game_state.players[3].hand.end(), MyDataSortPredicate);
-
-
- most_value_action.type = Action::Pass;
- current_player = 3;
- num_player_actions = 0;
- draw_phase = true;
-
-}
-
-
-State& Standard::round_update() {
- char smart = 0;
- // We're in the draw_phase whenever a player draws a tile from the wall
- if(draw_phase) {
- // If the wall is empty (Contains only 14 tiles) when we enter draw phase the round is over.
-
- // Since we've entered the draw-phase it's the next players turn
- if (current_player == 3) {
- current_player = 0;
- } else {
- current_player++;
- }
-
- #ifdef DEBUG
-
- time_t current_time = std::time(0);
- std::cout << std::ctime(&current_time) << " - Waiting for action from player: " << current_player << std::endl;
-
- #endif
-
- // Let's take a tile
- Tile from_wall = wall.take_one();
-
- // We then add the tile to the current players hand
- game_state.players[current_player].hand.push_back(from_wall);
-
- // Need to sort again.
- std::sort(game_state.players[current_player].hand.begin(),game_state.players[current_player].hand.end(), MyDataSortPredicate);
-
- // Construct the discard action that the player can do.
- Action discard;
- discard.type = Action::Discard;
- //discard.player = current_player;
-
-
- game_state.possible_actions.push_back(discard);
-
- //num_player_actions++;
-
- // Enter the discard phase next loop;
- draw_phase = false;
- smart = smart | (1 << current_player);
- } else {
-
- int temp_next_player;
- if (current_player == 3) {
- temp_next_player = 0;
- } else {
- temp_next_player = current_player + 1;
- }
-
- Tiles* pond = &game_state.players[current_player].pond;
- Tile temp_tile = pond->back();
- Tiles::iterator it;
-
- //We check to see if any players have kan/pon
- unsigned int tile_match_ids[3];
- unsigned int count, count_m;
- for(unsigned int array_counter = 0; array_counter < 4; array_counter++) {
- State::Player* temp_player = &game_state.players[array_counter];
- count = 0;
- count_m = 0;
- for(it = temp_player->hand.begin(); it != temp_player->hand.end(); ++it) {
- if(it->type == temp_tile.type) {
- tile_match_ids[count_m] = count;
- count_m++;
- }
- count++;
- }
-
- if(tile_match_ids[1]) {
- Action temp_action;
- //temp_action.player = array_counter;
- //temp_action.target.push_back(tile_match_ids[0]);
- //temp_action.target.push_back(tile_match_ids[1]);
- temp_action.type = Action::Pon;
- game_state.possible_actions.push_back(temp_action);
- }
-
- if(tile_match_ids[2]) {
- Action temp_action;
- //temp_action.player = array_counter;
- //temp_action.target.push_back(tile_match_ids[0]);
- //temp_action.target.push_back(tile_match_ids[1]);
- //temp_action.target.push_back(tile_match_ids[2]);
- temp_action.type = Action::Kan;
- game_state.possible_actions.push_back(temp_action);
- }
- }
-
- //We check to see if player can chi from last discard
- Tile* tile_2u = NULL;
- Tile* tile_1u = NULL;
- Tile* tile_1o = NULL;
- Tile* tile_2o = NULL;
- unsigned int tile_2u_id,tile_1u_id,tile_1o_id,tile_2o_id;
- count = 0;
- Tile::Type check_tile;
- for(it = game_state.players[temp_next_player].hand.begin(); it != game_state.players[temp_next_player].hand.end(); ++it) {
- #ifdef DEBUG
- Tile debug = *it;
- #endif
-
- check_tile = Tile::Type(temp_tile.type - 2);
- if(it->type == check_tile) {
- tile_2u = &(*it);
- tile_2u_id = count;
- }
- check_tile = Tile::Type(temp_tile.type - 1);
- if(it->type == check_tile) {
- tile_1u = &(*it);
- tile_1u_id = count;
- }
- check_tile = Tile::Type(temp_tile.type + 1);
- if(it->type == check_tile) {
- tile_1o = &(*it);
- tile_1o_id = count;
- }
- check_tile = Tile::Type(temp_tile.type + 2);
- if(it->type == check_tile) {
- tile_2o = &(*it);
- tile_2o_id = count;
- }
- count++;
- }
-
- bool chi;
- if(tile_2u && tile_1u) {
- Action temp_action;
- chi = false;
- //Make sure we have a chi within the same series.
- if(tile_2u->type <= Tile::Man_7 && tile_2u->type >= Tile::Man_1) {
- chi = true;
- } else if(tile_2u->type <= Tile::Pin_7 && tile_2u->type >= Tile::Pin_1) {
- chi = true;
- } else if(tile_2u->type <= Tile::Sou_7 && tile_2u->type >= Tile::Sou_1) {
- chi = true;
- }
- if(chi) {
- //temp_action.player = temp_next_player;
- //temp_action.target.push_back(tile_2u_id);
- //temp_action.target.push_back(tile_1u_id);
- temp_action.type = Action::Chi;
- game_state.possible_actions.push_back(temp_action);
- #ifdef DEBUG
-
- //time_t current_time = std::time(0);
- //std::cout << std::ctime(&current_time) << " Player: " << temp_action.player << " Can do action: " << temp_action.type << " On target: " << temp_action.target[0] << std::endl;
-
- #endif
- }
- }
-
- if(tile_1u && tile_1o) {
- Action temp_action;
- chi = false;
- //Make sure we have a chi within the same series.
- if(tile_1u->type <= Tile::Man_7 && tile_1u->type >= Tile::Man_1) {
- chi = true;
- } else if(tile_1u->type <= Tile::Pin_7 && tile_1u->type >= Tile::Pin_1) {
- chi = true;
- } else if(tile_1u->type <= Tile::Sou_7 && tile_1u->type >= Tile::Sou_1) {
- chi = true;
- }
- if(chi) {
- //temp_action.player = temp_next_player;
- //temp_action.target.push_back(tile_1u_id);
- //temp_action.target.push_back(tile_1o_id);
- temp_action.type = Action::Chi;
- game_state.possible_actions.push_back(temp_action);
-
- #ifdef DEBUG
-
- //time_t current_time = std::time(0);
- //std::cout << std::ctime(&current_time) << " Player: " << temp_action.player << " Can do action: " << temp_action.type << " On target: " << temp_action.target[0] << std::endl;
-
- #endif
- }
- }
-
- if(tile_1o && tile_2o) {
- Action temp_action;
- chi = false;
- //Make sure we have a chi within the same series.
- if(temp_tile.type <= Tile::Man_7 && temp_tile.type >= Tile::Man_1) {
- chi = true;
- } else if(temp_tile.type <= Tile::Pin_7 && temp_tile.type >= Tile::Pin_1) {
- chi = true;
- } else if(temp_tile.type <= Tile::Sou_7 && temp_tile.type >= Tile::Sou_1) {
- chi = true;
- }
- if(chi) {
- //temp_action.player = temp_next_player;
- //temp_action.target.push_back(tile_1o_id);
- //temp_action.target.push_back(tile_2o_id);
- temp_action.type = Action::Chi;
- game_state.possible_actions.push_back(temp_action);
-
- #ifdef DEBUG
-
- //time_t current_time = std::time(0);
- //std::cout << std::ctime(&current_time) << " Player: " << temp_action.player << " Can do action: " << temp_action.type << " On target: " << temp_action.target[0] << std::endl;
-
- #endif
- }
- }
-
- //Go back into draw_phase0
- draw_phase = true;
- // Not implemented yet
-
- for(Actions::iterator it = game_state.possible_actions.begin(); it != game_state.possible_actions.end(); ++it) {
- //smart = smart | (0x0001 << it->player);
- }
-
- if(smart & 1) {
- Action pass;
- pass.type = Action::Pass;
- //pass.player = 0;
- game_state.possible_actions.push_back(pass);
- }
- if(smart & 2) {
- Action pass;
- pass.type = Action::Pass;
- //pass.player = 1;
- game_state.possible_actions.push_back(pass);
- }
- if(smart & 4) {
- Action pass;
- pass.type = Action::Pass;
- //pass.player = 2;
- game_state.possible_actions.push_back(pass);
- }
- if(smart & 8) {
- Action pass;
- pass.type = Action::Pass;
- //pass.player = 3;
- game_state.possible_actions.push_back(pass);
- }
- }
-
- for(Actions::iterator it = game_state.possible_actions.begin(); it != game_state.possible_actions.end(); ++it) {
- //smart = smart | (1 << it->player);
- }
-
- if(smart & 1) {
- num_player_actions++;
- }
- if(smart & 2) {
- num_player_actions++;
- }
- if(smart & 4) {
- num_player_actions++;
- }
- if(smart & 8) {
- num_player_actions++;
- }
-
- if(num_player_actions == 0) {
- draw_phase = true;
- }
-
- return game_state;
-}
-
-bool Standard::round_action(Action action) {
- #ifdef DEBUG
-
- //time_t current_time = std::time(0);
- //std::cout << std::ctime(&current_time) << " Player: " << action.player << " Did action: " << action.type << " On target: " << action.target[0] << std::endl;
-
- #endif
-
- // Lots of actions to test if the player doing the action is allowed to do it
-
- // Check if we're actually waiting for actions.
- if (game_state.possible_actions.empty()) {
- return false;
- }
-
- // Check if the player is allowed to do this action
- bool found_action = false;
-
- for(Actions::iterator it = game_state.possible_actions.begin(); it != game_state.possible_actions.end(); ++it) {
- //if(it->player == action.player && it->type == action.type) {
- // found_action = true;
- //}
- }
-
- if(!found_action) {
- return false;
- }
-
- switch ( action.type ) {
-
- case Action::Pass: {
-
- } break;
-
- case Action::Discard: {
- //Tile discarded_tile = game_state.players[action.player].hand[action.target[0]];
- //game_state.players[action.player].pond.push_back(discarded_tile);
- //game_state.players[action.player].hand.erase(game_state.players[action.player].hand.begin() + action.target[0]);
-
- } break;
-
- case Action::Riichi: {
-
- } break;
-
- case Action::Chi: {
- if(most_value_action.type != Action::Pon && most_value_action.type != Action::Kan && most_value_action.type != Action::Ron) {
- most_value_action = action;
- }
- } break;
-
- case Action::Pon: {
- if(most_value_action.type != Action::Ron) {
- most_value_action = action;
- }
- } break;
-
- case Action::Kan: {
-
- } break;
-
- case Action::Ron: {
-
- } break;
-
- case Action::Tsumo: {
-
- } break;
-
- case Action::Draw: {
-
- } break;
-
- default:
- break;
- }
-
-
- num_player_actions--;
-
- // Remove all the actions that this player could do since he now did one.
-
- std::vector<int> positions;
- int position = 0;
- for(Actions::iterator it = game_state.possible_actions.begin(); it != game_state.possible_actions.end(); ++it) {
- //if (it->player == action.player) {
- // positions.push_back(position);
- //}
- position++;
- }
- if (!positions.empty()) {
- int found = 0;
- for(std::vector<int>::iterator it = positions.begin(); it != positions.end(); ++it) {
- game_state.possible_actions.erase(game_state.possible_actions.begin() + (*it - found));
- found++;
- }
- }
-
- //When everyone has done their action we empty the list (just to be sure) and then do a round_update()
- if(num_player_actions == 0) {
- game_state.possible_actions.empty();
-
- if(most_value_action.type != Action::Pass) {
- switch (most_value_action.type) {
- case Action::Chi: {
- Tile left_tile = game_state.players[current_player].pond.back();
- left_tile.rotated = true;
- //game_state.players[action.player].open.push_back(left_tile);
-
- //int count = 0;
- //for(std::vector<int>::iterator it = most_value_action.target.begin(); it != most_value_action.target.end(); ++it) {
- // Tile target_tile = game_state.players[action.player].hand[(*it) - count];
- // game_state.players[action.player].open.push_back(target_tile);
- // game_state.players[action.player].hand.erase(game_state.players[action.player].hand.begin() + (*it) - count);
- // count++;
- //}
-
- Action discard;
- discard.type = Action::Discard;
- //discard.player = action.player;
- game_state.possible_actions.push_back(discard);
-
- draw_phase = false;
-
- } break;
-
- case Action::Pon: {
- Tile left_tile = game_state.players[current_player].pond.back();
- left_tile.rotated = true;
- //game_state.players[action.player].open.push_back(left_tile);
-
- //int count = 0;
- //for(std::vector<int>::iterator it = most_value_action.target.begin(); it != most_value_action.target.end(); ++it) {
- // Tile target_tile = game_state.players[action.player].hand[(*it) - count];
- // game_state.players[action.player].open.push_back(target_tile);
- // game_state.players[action.player].hand.erase(game_state.players[action.player].hand.begin() + (*it) - count);
- // count++;
- //}
-
- Action discard;
- discard.type = Action::Discard;
- //discard.player = action.player;
- game_state.possible_actions.push_back(discard);
-
- draw_phase = false;//player must discard extra tile
-
- //Play continues to the right
- //current_player = action.player;
-
- } break;
-
- case Action::Kan: {
- Tile left_tile = game_state.players[current_player].pond.back();
- left_tile.rotated = true;
- //game_state.players[action.player].open.push_back(left_tile);
-
- //int count = 0;
- //for(std::vector<int>::iterator it = most_value_action.target.begin(); it != most_value_action.target.end(); ++it) {
- // Tile target_tile = game_state.players[action.player].hand[(*it) - count];
- // game_state.players[action.player].open.push_back(target_tile);
- // game_state.players[action.player].hand.erase(game_state.players[action.player].hand.begin() + (*it) - count);
- // count++;
- //}
-
- Action discard;
- discard.type = Action::Discard;
- //discard.player = action.player;
- game_state.possible_actions.push_back(discard);
-
- draw_phase = false;//player must discard extra tile
-
- //Play continues to the right
- //current_player = action.player;
-
- } break;
-
- case Action::Ron: {
-
- } break;
-
- default: break;
- }
- most_value_action.type = Action::Pass;
- }
- return true;
- } else {
- return false;
- }
-}
diff --git a/server/standard.h b/server/standard.h
deleted file mode 100644
index 9ad73ec..0000000
--- a/server/standard.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef STANDARD_H
-#define STANDARD_H
-
-#include "gamevariant.h"
-#include "wall.h"
-#include "../common/set.h"
-
-namespace RuleSet {
- class Standard : public GameVariant {
- private:
- //! The wall that belongs to this game
- Wall wall;
-
- //! The current state of the game
- State game_state;
-
- //! Current player, used when discarding etc
- int current_player;
-
- //! Are we in draw or discard phase?
- bool draw_phase;
-
- //! Number of players doing action
- int num_player_actions;
-
- //! Highest value action done
- Action most_value_action;
-
- public:
- virtual void round_start();
- virtual State& round_update();
- virtual bool round_action(Action action);
- };
-};
-#endif // STANDARD_H
-