Clean up CXX Flags and remove statements relating to us being cool. If you have to say it, it ain't true
This commit is contained in:
parent
43a2c58c56
commit
7a75fbd369
15 changed files with 110 additions and 57 deletions
|
@ -7,9 +7,6 @@ include_directories(
|
|||
../maths
|
||||
)
|
||||
|
||||
# Set to use c++11, because we're cool like that
|
||||
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11" )
|
||||
|
||||
# Add the sources
|
||||
set( SOURCES
|
||||
game.cpp
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
ttrts Game Design
|
||||
=================
|
||||
|
||||
The game takes place in a series of simultanious turns on an arbitrarilly sized 2D board.
|
||||
The game takes place in a series of simultaneous turns on an arbitrarily sized 2D board.
|
||||
|
||||
Each player is in control of a set number of starting units, each turn recieves data on the status of the board.
|
||||
Each player is in control of a set number of starting units, each turn receives data on the status of the board.
|
||||
|
||||
Each player must then issue a single command to each unit in thier control.
|
||||
Each player must then issue a single command to each unit in their control.
|
||||
|
||||
The engine then takes all commands, evaluates all movement first simultaniously, then all other commands.
|
||||
The engine then takes all commands, evaluates all movement first simultaneously, then all other commands.
|
||||
|
||||
All attempted movement to the same square by two or more units will fail.
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "game.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string.h>
|
||||
|
||||
// Interpret a string of orders
|
||||
int CTTRTSGame::IssueOrders( player_id_t player, const std::string& _orders )
|
||||
|
@ -68,8 +69,8 @@ int CTTRTSGame::IssueOrder( player_id_t player, const COrder& order )
|
|||
int CTTRTSGame::VerifyPos(uvector2 vec) const
|
||||
{
|
||||
// Simply check if within the bounds of our dimensions for now
|
||||
if ( ( vec.x >= dimentions.x )
|
||||
|| ( vec.y >= dimentions.y ) )
|
||||
if ( ( vec.x >= dimensions.x )
|
||||
|| ( vec.y >= dimensions.y ) )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -224,20 +225,19 @@ int CTTRTSGame::SimulateToNextTurn()
|
|||
int CTTRTSGame::AddUnit( CUnit&& unit )
|
||||
{
|
||||
// Verify the unit
|
||||
const int val = unit.valid();
|
||||
if( val )
|
||||
return val;
|
||||
if( !unit.valid() )
|
||||
return 1;
|
||||
|
||||
// Verify if the unit can be placed on the current board
|
||||
const uvector2 pos = unit.getPos();
|
||||
if( (pos.x >= dimentions.x) || (pos.y >= dimentions.y) )
|
||||
return 1;
|
||||
if( (pos.x >= dimensions.x) || (pos.y >= dimensions.y) )
|
||||
return 2;
|
||||
|
||||
// If any unit's position matches, reject this
|
||||
for ( const OrderUnitPair& pair: m_OrderUnitPairs )
|
||||
{
|
||||
if( pair.unit.getPos() == unit.getPos() )
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
// Add the unit with a blank order
|
||||
|
@ -315,3 +315,40 @@ CUnit& CTTRTSGame::GetUnitByID( unit_id_t id )
|
|||
static CUnit invalid_unit;
|
||||
return invalid_unit;
|
||||
}
|
||||
|
||||
// Check if we have a win state
|
||||
Team CTTRTSGame::CheckForWin() const
|
||||
{
|
||||
// Array of units for each Team
|
||||
unsigned int units[(int) Team::NUM_INVALID];
|
||||
memset(units,0,sizeof(units));
|
||||
|
||||
// Count up all the units for each Team
|
||||
for ( const OrderUnitPair& pair : m_OrderUnitPairs )
|
||||
{
|
||||
const int team = (int)pair.unit.getTeam();
|
||||
units[team] += 1;
|
||||
}
|
||||
|
||||
// Default winning Team to invalid (no win)
|
||||
Team winningTeam = Team::NUM_INVALID;
|
||||
|
||||
// For each of the teams
|
||||
for ( unsigned int i = 0; i < _countof(units); i++ )
|
||||
{
|
||||
// if there are still units in this Team, and the winning Team hasn't been set
|
||||
if( units[i] > 0 && winningTeam == Team::NUM_INVALID )
|
||||
{
|
||||
winningTeam = (Team)i;
|
||||
}
|
||||
// Otherwise, if there are units in this Team and the winning Team HAS been set
|
||||
else if ( units[i] > 0 )
|
||||
{
|
||||
// Set back to invalid and break out of the loop
|
||||
winningTeam = Team::NUM_INVALID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return winningTeam;
|
||||
}
|
16
game/game.h
16
game/game.h
|
@ -35,7 +35,7 @@ class CTTRTSGame
|
|||
public:
|
||||
|
||||
CTTRTSGame( ucoord_t c, ucoord_t r )
|
||||
: dimentions( {c,r} )
|
||||
: dimensions( c,r )
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -72,17 +72,19 @@ public:
|
|||
// Get orders by index as above
|
||||
inline const COrder& GetOrdersByIndex( unsigned int i ) const { return m_OrderUnitPairs[i].order; }
|
||||
|
||||
// Get dimentions
|
||||
inline const uvector2& GetDimentions() const { return dimentions; }
|
||||
// Get dimensions
|
||||
inline const uvector2 &GetDimensions() const { return dimensions; }
|
||||
|
||||
// Check for a win, returns invalid for no win state reached
|
||||
// Note: this function will return invalid a draw was reached
|
||||
// best practice would be to call with GetNumUnits() == 0
|
||||
Team CheckForWin() const;
|
||||
|
||||
private:
|
||||
|
||||
// Verify any order - non-zero is error
|
||||
int VerifyOrder( player_id_t player, const COrder& order ) const;
|
||||
|
||||
// Verify any order - non-zero is error
|
||||
int VerifyUnit( const CUnit& unit ) const;
|
||||
|
||||
// Verify Position - non-zero is error
|
||||
int VerifyPos( uvector2 vec ) const;
|
||||
|
||||
|
@ -99,7 +101,7 @@ private:
|
|||
CUnitVector m_deadUnits;
|
||||
|
||||
// Dimensions of the game
|
||||
uvector2 dimentions;
|
||||
uvector2 dimensions;
|
||||
};
|
||||
|
||||
#endif //_GAME_H_
|
||||
|
|
|
@ -4,25 +4,27 @@
|
|||
#include <limits> // std::numeric_limits
|
||||
|
||||
// Type for a team IDs
|
||||
typedef unsigned short team_id_t;
|
||||
enum class Team : char
|
||||
{
|
||||
Red = 0,
|
||||
Blue,
|
||||
Green,
|
||||
Yellow,
|
||||
NUM_INVALID
|
||||
};
|
||||
|
||||
// Type for player IDs
|
||||
typedef unsigned short player_id_t;
|
||||
typedef unsigned char player_id_t;
|
||||
|
||||
// Type for unit IDs
|
||||
typedef unsigned short unit_id_t;
|
||||
|
||||
// Type for the unit type-id
|
||||
typedef char unitType_c;
|
||||
|
||||
// Typedef for unit visual representations
|
||||
typedef char unitVis_c;
|
||||
|
||||
// Invalid data for above types
|
||||
static const team_id_t team_id_invalid = std::numeric_limits<team_id_t>::max();
|
||||
static const player_id_t player_id_invalid = std::numeric_limits<player_id_t>::max();
|
||||
static const unit_id_t unit_id_invalid = std::numeric_limits<unit_id_t>::max();
|
||||
static const unitType_c unitType_invalid = std::numeric_limits<unitType_c>::max();
|
||||
static const unitVis_c unitVis_invalid = std::numeric_limits<unitVis_c>::max();
|
||||
|
||||
#endif //_GAME_TYPES_H_
|
|
@ -24,7 +24,7 @@ COrder GetOrderFromString( const std::string& _order )
|
|||
{
|
||||
const std::string order_unit = order.substr(0, pos);
|
||||
|
||||
ret.unit = atoi( order_unit.c_str() );
|
||||
ret.unit = (unit_id_t)atoi( order_unit.c_str() );
|
||||
|
||||
// Erase everything up to and including the delimiter
|
||||
order.erase(0, pos + 1);
|
||||
|
|
|
@ -15,7 +15,7 @@ enum class order_c : char
|
|||
L = 'L',
|
||||
R = 'R',
|
||||
A = 'A',
|
||||
INVALID
|
||||
NUM_INVALID
|
||||
};
|
||||
|
||||
// Container for an order
|
||||
|
@ -24,7 +24,7 @@ struct COrder
|
|||
// Base constructor makes invalid order
|
||||
COrder()
|
||||
: unit ( unit_id_invalid )
|
||||
, order ( order_c::INVALID )
|
||||
, order ( order_c::NUM_INVALID )
|
||||
{}
|
||||
|
||||
// Unit order is for
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace
|
|||
// Plain constructor
|
||||
CUnit::CUnit()
|
||||
: unit_id ( get_unique_unit_id() )
|
||||
, team_id ( team_id_invalid )
|
||||
, team_id ( Team::NUM_INVALID )
|
||||
, unit_vis ( unitVis_invalid )
|
||||
, player_id ( player_id_invalid )
|
||||
, dir ( dir_t::S )
|
||||
|
|
13
game/unit.h
13
game/unit.h
|
@ -24,15 +24,14 @@ public:
|
|||
|
||||
// Getters for all the members
|
||||
inline const unit_id_t& getID() const { return unit_id; }
|
||||
inline const team_id_t& getTeam() const { return team_id; }
|
||||
inline const Team & getTeam() const { return team_id; }
|
||||
inline const player_id_t& getPlayer() const { return player_id; }
|
||||
inline const unitVis_c& getVisual() const { return unit_vis; }
|
||||
inline const dir_t& getDir() const { return dir; }
|
||||
|
||||
// Return non-zero values on error
|
||||
inline int setTeam(const team_id_t& v) { return (v == team_id_invalid) ? -1 : (( team_id = v ), 0); }
|
||||
inline int setPlayer(const player_id_t& v) { return (v == player_id_invalid) ? -1 : (( player_id = v ), 0); }
|
||||
inline int setVisual(const unitVis_c& v) { return (v == unitVis_invalid) ? -1 : (( unit_vis = v ), 0); }
|
||||
inline Team setTeam(const Team & v) { return (team_id = v); }
|
||||
inline player_id_t setPlayer(const player_id_t& v) { return ( player_id = v ); }
|
||||
inline unitVis_c setVisual(const unitVis_c& v) { return ( unit_vis = v ); }
|
||||
|
||||
// Set unit direction
|
||||
inline dir_t setDir(const dir_t& v) { return (dir = v); }
|
||||
|
@ -69,7 +68,7 @@ private:
|
|||
unitVis_c unit_vis;
|
||||
|
||||
// Team ID
|
||||
team_id_t team_id;
|
||||
Team team_id;
|
||||
|
||||
// Owner ID
|
||||
player_id_t player_id;
|
||||
|
@ -88,7 +87,7 @@ typedef std::vector< CUnit > CUnitVector;
|
|||
inline bool CUnit::valid() const
|
||||
{
|
||||
return (unit_id != unit_id_invalid )
|
||||
&& (team_id != team_id_invalid )
|
||||
&& (team_id != Team::NUM_INVALID )
|
||||
&& (player_id != player_id_invalid)
|
||||
&& (unit_vis != unitVis_invalid);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue