Skip to content

Commit

Permalink
Merge development branch
Browse files Browse the repository at this point in the history
* minor change to order of included headers

* a try to correct linker error

* Removed explicit inlining

* Removed static from definition of static member function

* Shifted from Make builds to CMake build

* Update README.md
  • Loading branch information
adi-g15 authored Sep 6, 2020
1 parent d8f0542 commit a9f3eb6
Show file tree
Hide file tree
Showing 22 changed files with 78 additions and 95 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/ccpp.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/af9190f3627842869828fb1c8307b818)](https://app.codacy.com/manual/AdityaGupta150/Ludo-The_Game?utm_source=github.com&utm_medium=referral&utm_content=AdityaGupta150/Ludo-The_Game&utm_campaign=Badge_Grade_Dashboard)
![C/C++ CI](https://github.com/AdityaGupta150/Ludo-The_Game/workflows/C/C++%20CI/badge.svg)
![CMake](https://github.com/AdityaGupta150/Ludo-The_Game/workflows/CMake/badge.svg)
[![Build Status](https://travis-ci.org/AdityaGupta150/Ludo-The_Game.svg?branch=master)](https://travis-ci.org/AdityaGupta150/Ludo-The_Game)

# Ludo - The Game v2.0
Expand Down
4 changes: 2 additions & 2 deletions extras/Comments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ includes/utilities
*/
/*[LEARNT] To point to member functions, we need to have "Member pointers"
NOTE - Member pointers can't point to non-member functions, and normal function pointers can point to class member functions
typedef (void)(game::*functionPointer)(); //Member pointer, BUT STILL USING 'game::' is required when we will be using it
typedef (void)(*functionPointer)(); //Normal function pointers
typedef ()(game::*functionPointer)(); //Member pointer, BUT STILL USING 'game::' is required when we will be using it
typedef ()(*functionPointer)(); //Normal function pointers
*/

/*LEARNT - We can't create a dynamically allocated array of objects of a class with no default constructor using 'new' -
Expand Down
7 changes: 4 additions & 3 deletions includes/boardPrinter.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once

#include <iostream>
#include <array>
#include "ludo_box.hpp"
#include "util/terminal.hpp"

#include <iostream>
#include <array>

class _BoardPrinter{ //! @info Only for use by updateDisplay() & takeIntro()
private:
/*@note Also clears the screen, so that the titlebar is at top
Expand All @@ -16,7 +17,7 @@ class _BoardPrinter{ //! @info Only for use by updateDisplay() & takeIntro()
static void titleBar(); /*@brief Simply just calls titleBar with (terminalDimen().first)*/
static void msgScreen(const std::string& msg);
static void errorScreen(const std::string& errMsg);
static void finishedScreen(void);
static void finishedScreen();
/*FUTURE - It can be modified to show who's the 1st and who's the 4th, BUT FOR NOW I WILL NOT IMPLEMENT IT HERE, SINCE I HAVE FURTHER PENDING PLANS FOR GUI*/

void row_type1(int nrow);
Expand Down
2 changes: 1 addition & 1 deletion includes/die.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Die{
static std::array<std::mt19937, 4> mt = { std::mt19937(dev_engine()),std::mt19937(dev_engine()),std::mt19937(dev_engine()),std::mt19937(dev_engine()) };
static std::array<std::uniform_int_distribution<int>, 4> dist = { std::uniform_int_distribution<int>(1,6), std::uniform_int_distribution<int>(1,6), std::uniform_int_distribution<int>(1,6), std::uniform_int_distribution<int>(1,6) }; //uniform distribution from [1,6]

std::vector<_dieVal> rolldie(void); //! Undelete, if YOU like that version of rollDie
std::vector<_dieVal> rolldie(); //! Undelete, if YOU like that version of rollDie
void rolldie(std::vector<_dieVal>&);

}
28 changes: 14 additions & 14 deletions includes/game.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "die.hpp"
#include "ludo_state.hpp"
#include "ludo_box.hpp"
#include "exceptions.hpp"
#include "ludo_box.hpp"
#include "ludo_state.hpp"

#include <map>
#include <set>
Expand All @@ -26,7 +26,7 @@ class ludo_state;
class game
{
private:
typedef void (game::*functionPointer)(void);
typedef void (game::*functionPointer)();

std::vector<std::vector<ludo_box>> board;
std::map<_colour, std::vector<std::reference_wrapper<ludo_box>>> lockedPositions;
Expand All @@ -43,15 +43,15 @@ class game

ludo_coords _ludo_coords; //! An object to make the ludo_coords available to us

inline bool gameisFinished(void);
inline bool isPlayerPlaying(player);
bool gameisFinished();
bool isPlayerPlaying(player);
unsigned getNumLockedGotis(_colour);
/* @brief Simply moves a goti of same colour from the locked goti positions,
and move the goti to movingGotis, and the std::make_shared to starting box
@returns bool indicating whether enough locked gotis were available*/
bool unlockGoti(void);
bool unlockGoti();
bool lockGoti(std::shared_ptr<ludo_goti>);
void takeIntro(void); //! Initializes the PlayerMap
void takeIntro(); //! Initializes the PlayerMap
void endGame() const; //Only for use by shortcutsMap, and DEBUGGING purpose
void endGame(std::string cause) const;

Expand All @@ -73,7 +73,7 @@ class game
std::map<player, std::pair<std::string, _colour>> activePlayerMap;
std::map<player, RobotKind> robotPlayers;

inline short moveGoti(std::shared_ptr<ludo_goti>, unsigned int dist);
short moveGoti(std::shared_ptr<ludo_goti>, unsigned int dist);
short moveGoti(std::shared_ptr<ludo_goti>, _smartMoveData moveData); //Moves goti to ENDPOINT 'DIRECTLY' (basic checks only)
bool handleMoveVal(short, std::vector<_dieVal> &dieNumbers, bool isRobot = true); //Handles value returned by moveGoti() calls

Expand All @@ -87,20 +87,20 @@ class game
*/
void attack(std::vector<_colour> coloursToRemove, std::shared_ptr<ludo_goti> attacker);

void updateDisplay(void);
void updateDisplay();
/*NOTE - getEmptyLocks(...) == {0,0} is a good test for 'ZERO LOCKED POSITIONS'*/
_coord getEmptyLocks(_colour) const;

bool InitGame(short = 1); //! Starts/Resets the game
void play(bool = true);
void settingsMenu();
void notYetImplementedScr(void) const;
inline ludo_box &getBoardBox(const _coord &coords);
inline const ludo_box &getBoardBox(const _coord &coords) const;
void notYetImplementedScr() const;
ludo_box &getBoardBox(const _coord &coords);
const ludo_box &getBoardBox(const _coord &coords) const;

//Current State Validation Methods
inline bool isValid(const _coord &coords) const;
inline bool isValid(const std::shared_ptr<ludo_goti> &) const;
bool isValid(const _coord &coords) const;
bool isValid(const std::shared_ptr<ludo_goti> &) const;

game();
~game();
Expand Down
3 changes: 2 additions & 1 deletion includes/keywords.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
*/
#pragma once

#include "enumerations.hpp"

#include <string>
#include <map>
#include "enumerations.hpp"

static std::string robot_keyword = "ROBOT";

Expand Down
5 changes: 3 additions & 2 deletions includes/ludo_box.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "ludo_goti.hpp"

#include <vector>
#include <memory>
#include <map>
Expand All @@ -20,9 +21,9 @@ class ludo_box{
//! Returns 0 if attacked other goti, -1 if unsuccessful; In most cases, this return value will be ignored, only in moveGoti functions it work
short appendGoti(std::shared_ptr<ludo_goti>);
std::string get_box_content() const;
void sanitizeContent(void);
void sanitizeContent();
bool isPresent(const ludo_goti& goti) const;
inline bool isEmpty(void) const;
bool isEmpty() const;

bool areOpponentsPresent(_colour) const;

Expand Down
5 changes: 3 additions & 2 deletions includes/ludo_coords.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "enumerations.hpp"

#include <map>
#include <vector>
#include <functional>
#include "enumerations.hpp"

class ludo_coords{
public:
Expand All @@ -15,7 +16,7 @@ class ludo_coords{
friend class game;
public:

void InitCoords(void);
void InitCoords();
direction turnAtCorner(const _coord& curr_coords, const std::map<_coord, direction>&) const;
ludo_coords();
};
5 changes: 3 additions & 2 deletions includes/ludo_goti.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <functional>
#include "enumerations.hpp"

#include <functional>

class ludo_goti{
private:
const _colour gotiColour;
Expand All @@ -12,7 +13,7 @@ class ludo_goti{
public:
_coord getCoords() const;
direction get_curr_direction() const;
_colour get_gotiColour(void) const;
_colour get_gotiColour() const;

friend class game;
friend class ludo_box;
Expand Down
11 changes: 5 additions & 6 deletions includes/ludo_state.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#include "enumerations.hpp"
#include "ludo_coords.hpp"
#include "forward_decl.hpp"

/*@brief It 'will' be a class to store the 'states' of the game at that time, for which the state is created.
1. I thought of this kind of feature to be highly helpful in saving, loading, resetting the game, and only this much data as available in a ludo_state object will be required.
2. It was also thought of being highly helpful, to the AI algorithm i was trying to develop -
Expand All @@ -12,11 +16,6 @@
If you like it, and succeed in developing this, first of all I will be very thankful, secondly, you keep all the AI credits! :D
*/

#include "enumerations.hpp"
#include "ludo_coords.hpp"

class game;

#include <set>

class state_goti{
Expand All @@ -38,7 +37,7 @@ class state_box{
std::vector<state_goti*> inBoxGotis;
public:
BOX_TYPE type;
inline bool appendGoti(state_goti*);
bool appendGoti(state_goti*);
state_goti* removeGoti(state_goti*); //It doesn't delete the goti pointer, delete it yourself, from returned pointer or use this pointer to append somewhere else
bool areOpponentsPresent(_colour) const;

Expand Down
6 changes: 3 additions & 3 deletions includes/thinker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class thinker{

public:
bool unlock(); //! Only friend 'thinker' can use these to modify the class
inline bool move();
inline bool operator()(); //Both, move(), and the () operator will call 'getBestMove'
bool move();
bool operator()(); //Both, move(), and the () operator will call 'getBestMove'

static inline direction getDirOfMovement(const _coord &);
static direction getDirOfMovement(const _coord &);
const std::optional<_smartMoveData> isMovePossible(const _coord &, int dist) const; //! This will use 'currColour from state only'

//NOTE - A consideration that has been used is, that when any move is made by any colour, then its goti CANT BE REMOVED, so the indexes of gotis that will be in combination will be valid for the whole move, since neither their order will change being in a set*/
Expand Down
10 changes: 5 additions & 5 deletions src/game.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "game.hpp"
#include "boardPrinter.hpp"
#include "exceptions.hpp"
#include "keywords.hpp"
#include "exceptions.hpp"
#include "boardPrinter.hpp"
#include "game.hpp"
#include "thinker.hpp"
#include "util/find_remove.hpp"
#include "util/string_util.hpp"
Expand All @@ -19,7 +19,7 @@ using namespace std;

//@todo - Remove it after successfully solving problem with util/stream_util.hpp
template <typename T1, typename T2> //Utility function
static inline std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p)
static std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p)
{
return out << '(' << p.first << ", " << p.second << ')';
}
Expand Down Expand Up @@ -139,7 +139,7 @@ short game::moveGoti(std::shared_ptr<ludo_goti> the_goti, unsigned int dist)
return -1;
}

//For this function, the move will initially be considered 'possible', since it is meant to be called through the inline overloads
//For this function, the move will initially be considered 'possible', since it is meant to be called through the overloads
short game::moveGoti(std::shared_ptr<ludo_goti> the_goti, _smartMoveData moveData)
{
if (!isValid(moveData.finalCoords) || getBoardBox(moveData.finalCoords).box_type == _boxUNUSABLE)
Expand Down
8 changes: 4 additions & 4 deletions src/ludo_box.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "ludo_box.hpp"

#include "exceptions.hpp"
#include "keywords.hpp"
#include "ludo_box.hpp"

#include <iostream>
#include <utility> //ONLY for creating a temp pair, in appendGoti()
#include <algorithm>
Expand All @@ -10,7 +10,7 @@
using namespace std;

template<typename T1, typename T2> //Utility function
static inline std::ostream& operator<<(std::ostream& out, const std::pair<T1,T2>& p){
static std::ostream& operator<<(std::ostream& out, const std::pair<T1,T2>& p){
return out<<'('<<p.first<<", "<<p.second<<')';
}

Expand Down Expand Up @@ -92,7 +92,7 @@ string ludo_box::get_box_content() const{
return content;
}

void ludo_box::sanitizeContent(void){
void ludo_box::sanitizeContent(){
std::array<char, 4> gotiChar = {'R', 'G', 'Y', 'B'};

for( auto &i : gotiChar ){
Expand Down
4 changes: 2 additions & 2 deletions src/ludo_goti.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "ludo_coords.hpp"
#include "ludo_goti.hpp"

#include <iostream>
#include "ludo_coords.hpp"

_coord ludo_goti::getCoords() const{
if(curr_coords.first == 0 && curr_coords.second == 0){
Expand All @@ -14,7 +14,7 @@ direction ludo_goti::get_curr_direction() const{
return curr_direction;
}

_colour ludo_goti::get_gotiColour(void) const{
_colour ludo_goti::get_gotiColour() const{
return gotiColour;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ludo_state.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "ludo_state.hpp"
#include "game.hpp"
#include "ludo_state.hpp"
#include "thinker.hpp"

using namespace std;
Expand Down
2 changes: 1 addition & 1 deletion src/thinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool thinker::unlock()
return true;
}

inline direction thinker::getDirOfMovement(const _coord &coord)
direction thinker::getDirOfMovement(const _coord &coord)
{
direction retVal;
if (coord.first < (15 / 2 - 2) || coord.second > (15 / 2 - 2))
Expand Down
Loading

0 comments on commit a9f3eb6

Please sign in to comment.