Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
bd7c06c
initial commit for gitignore, README, and a test starter script
idraper Apr 5, 2019
7db3ea0
added SimpleJSON to include and moved main to source.py. Working inte…
idraper Apr 5, 2019
9ec71dd
setup the cmake structure properly and created the gamelib library
idraper Apr 5, 2019
1cc656a
modified include files to work with linux as well as CMakeLists
idraper Apr 6, 2019
4542c82
replaced json library to use json11 (from SimpleJson)
idraper Apr 6, 2019
1ac37ee
finished some key functions for utilities and created custom exceptio…
idraper Apr 6, 2019
1a99535
quick fix with path for linux games
idraper Apr 6, 2019
b705223
added headers for each file and some basic comments
idraper Apr 6, 2019
029aac7
Added AlgoCore and AlgoStrategy just in basic structure. Also modifie…
idraper Apr 6, 2019
ed46805
made AlgoStrategy override AlgoCore functions.
idraper Apr 7, 2019
18058f2
switched utilties library to be util
idraper Apr 7, 2019
37e744a
added common enums and structs files and otherbasic setup for AlgoStr…
idraper Apr 7, 2019
5d6391f
created initial GameState class
idraper Apr 7, 2019
0a62fce
Added ability for GameState to parse the json to various structs.
idraper Apr 7, 2019
54e449d
added information about the algo in the README
idraper Apr 7, 2019
73335e7
Merge branch 'develop' into game_state_feature
idraper Apr 7, 2019
84c029d
fixed typo in README
idraper Apr 7, 2019
e9ec0ab
made the unit struct complete and updated the parser for it
idraper Apr 7, 2019
3e68447
continued adding functions to GameState. Now sends command using subm…
idraper Apr 7, 2019
1f31e08
continue to write funcions for GameState
idraper Apr 7, 2019
69b6fd8
finished main fuctions in GameState minus error checking and ones dep…
idraper Apr 7, 2019
d75ac77
fixed bug with rounding (for linux) and extra declaration
idraper Apr 7, 2019
a5a0808
removed util check
idraper Apr 7, 2019
97cdfea
initial (compiling) game unit files
RyanDraves Apr 8, 2019
a76a4ef
Merge branch 'develop' of https://github.com/idraper/C1GamesStarterKi…
RyanDraves Apr 8, 2019
c9b71aa
README update, .ignore for binaries
RyanDraves Apr 8, 2019
202dad1
removed the unit struct and where the gameState creates them in prepa…
idraper Apr 8, 2019
cfbd48b
updated headers
idraper Apr 8, 2019
a0c4edd
Merge pull request #2 from idraper/game_state_feature
idraper Apr 8, 2019
1a29e08
Merge branch 'develop' into feature/game_unit-develop
idraper Apr 8, 2019
717d02f
Made debugWrite more versitle and gave objects default toString funct…
idraper Apr 8, 2019
7283a74
Merge pull request #3 from idraper/feature/display_option
idraper Apr 8, 2019
6c4c738
initial creating of GameMap
idraper Apr 8, 2019
572913b
fixed style errors
RyanDraves Apr 8, 2019
4e9c386
.at() array access fix
RyanDraves Apr 8, 2019
0a99719
merge conflict auto resolved?
RyanDraves Apr 8, 2019
f7551e7
more merge conflicts?
RyanDraves Apr 8, 2019
9186a37
manual merge conflict resolution
RyanDraves Apr 8, 2019
76079d6
camel case fix
RyanDraves Apr 8, 2019
2d1d112
Added most GameMap functions.
idraper Apr 8, 2019
1a45a8a
dependency name fix
RyanDraves Apr 8, 2019
bbd6e28
saving progress on function
idraper Apr 8, 2019
15d549d
game unitStr a specified hash function and updated CMakeLists
idraper Apr 8, 2019
ef30785
removed old unordered map for tracking string representation
idraper Apr 8, 2019
86ca2ec
merge errors yay
RyanDraves Apr 8, 2019
845c2fc
Merge branch 'hotfix/compile_errors' of https://github.com/idraper/C1…
RyanDraves Apr 8, 2019
4664335
Removed stoi/stof
idraper Apr 8, 2019
456d54b
Merge pull request #1 from RyanDraves/feature/game_unit-develop
idraper Apr 8, 2019
1ae1410
Merge branch 'develop' into feature/game_map
idraper Apr 8, 2019
613ab24
merge
RyanDraves Apr 8, 2019
6c08372
more conflicts...
RyanDraves Apr 8, 2019
8556046
updated algoCore to fix stateType not being converted to string for e…
idraper Apr 8, 2019
086a840
fixed missing header iostream
idraper Apr 8, 2019
aa20630
made GameUnit printable by Util
idraper Apr 8, 2019
ad3bc9d
Merge branch 'develop' into feature/game_map
idraper Apr 8, 2019
ed642ab
Merge branch 'develop' of https://github.com/idraper/C1GamesStarterKi…
RyanDraves Apr 8, 2019
6aeccd2
had to add unit files to CMakeLists
idraper Apr 8, 2019
8b3d3a5
Added more functionality to the GameMap
idraper Apr 8, 2019
7f21dbc
Added navigation files for path finding
Paprikadobi Apr 8, 2019
9926071
add unit/ease of access implemented for game map
RyanDraves Apr 8, 2019
51c6ef7
bad merge, needs fix
RyanDraves Apr 8, 2019
532e794
initial game map implementations
RyanDraves Apr 9, 2019
7c2ed5a
manually resolved merge issues
RyanDraves Apr 9, 2019
25e346b
.at() vector access fix and synax error fix
Paprikadobi Apr 9, 2019
c171f60
change include path, added Node initializer
Paprikadobi Apr 9, 2019
92a3e07
Added functions to add and remove units. Finished except for function…
idraper Apr 9, 2019
2bd15ba
fixed bug with unit remove name (was RF). Added support for more flex…
idraper Apr 9, 2019
4d4da1e
made parameter names more descriptive
idraper Apr 9, 2019
667080c
added default functions to header.
idraper Apr 9, 2019
0a8655b
added remaining functions to AlgoStrategy. Needs changes once merged …
idraper Apr 9, 2019
4380bd1
made the starter strategy actually build. IMPORTANT: Bugged, since it…
idraper Apr 10, 2019
9a90f62
updated headers
idraper Apr 10, 2019
5857ebf
minor comment changes
idraper Apr 10, 2019
3a9b088
added a printError function for VERBOSE levels of printing errors
idraper Apr 10, 2019
52e5af6
merge develop -> feature/game_map
idraper Apr 10, 2019
a51a477
Merge branch 'develop' into feature/game_state
idraper Apr 10, 2019
1cf5a7c
Merge branch 'feature/game_state' into feature/starter_strategy
idraper Apr 10, 2019
c26365b
Filled in GameState errors and gave the ability to set the verbosity …
idraper Apr 10, 2019
cd0b4d2
Merge branch 'feature/game_state' into feature/starter_strategy
idraper Apr 10, 2019
ccbac69
added line to suppress warnings
idraper Apr 10, 2019
7702e1d
changes
RyanDraves Apr 10, 2019
44fe862
empty grid fix
RyanDraves Apr 10, 2019
d096cd2
Merge branch 'feature/game_map' of https://github.com/idraper/C1Games…
RyanDraves Apr 10, 2019
53578ca
uses new error system, printMap, and containsStationaryUnit
RyanDraves Apr 10, 2019
79594fb
Merge pull request #5 from RyanDraves/feature/game_map
idraper Apr 10, 2019
32eea71
Merge pull request #6 from idraper/feature/game_map
idraper Apr 10, 2019
ef8b296
Merge branch 'develop' into feature/game_state
idraper Apr 10, 2019
2787e39
fixed GameState error with player index after merge
idraper Apr 10, 2019
a184420
replaced all TODO's related to the GameMap and fixed merge errors
idraper Apr 10, 2019
5035d90
Merge pull request #7 from idraper/feature/game_state
idraper Apr 10, 2019
c73d9a2
Merge branch 'develop' into feature/starter_strategy
idraper Apr 10, 2019
56540f6
fixed merge errors
idraper Apr 10, 2019
3265377
Removed accidental change during testing.
idraper Apr 10, 2019
cb34e3a
Same as before
idraper Apr 10, 2019
5af4ed6
Merge pull request #8 from idraper/feature/starter_strategy
idraper Apr 10, 2019
459c4b0
fixed error with extra qualification in CustomExceptions
idraper Apr 10, 2019
4097528
Merge branch 'develop' into develop
idraper Apr 10, 2019
b34df31
Gamestate changed to gameGame in pathfinding
Paprikadobi Apr 11, 2019
0629006
Merge conflicts resolved
Paprikadobi Apr 11, 2019
0d77423
Merge conflicts
Paprikadobi Apr 11, 2019
1246530
Changes for navigation to work with GameMap
Paprikadobi Apr 11, 2019
2f848bb
Syntax changes
Paprikadobi Apr 11, 2019
a74d051
Bug fixes
Paprikadobi Apr 11, 2019
3880fca
fixed bug where inArenaBounds always return false
idraper Apr 11, 2019
9289c43
Fixed zig zag logic
Paprikadobi Apr 11, 2019
e6ae3ea
fixed conversion warning for stability being an int
idraper Apr 11, 2019
527ef36
Moved MOVE_DIRECTION to navigation.h
Paprikadobi Apr 11, 2019
1faa5df
reworked the order and structure of files and made functions const if…
idraper Apr 11, 2019
4d15a23
Removed debugWrite
Paprikadobi Apr 11, 2019
abb5220
Changed size_t to int
Paprikadobi Apr 11, 2019
1a3ac6a
Changed int to unsigned int
Paprikadobi Apr 11, 2019
402642c
began process of making ints unsigned
idraper Apr 11, 2019
d5e0d76
Merge pull request #4 from Paprikadobi/develop
idraper Apr 11, 2019
ad578ca
Merge branch 'develop' of https://github.com/idraper/C1GamesStarterKi…
idraper Apr 11, 2019
e29b07b
Revert "began process of making ints unsigned"
idraper Apr 11, 2019
4ab4f95
Merge branch 'develop' into style_refactoring
idraper Apr 12, 2019
7703492
changed integers to be unsigned
idraper Apr 12, 2019
866b0dd
checked all comments and style
idraper Apr 12, 2019
fab60a4
updated READMEs and added the findpath
idraper Apr 12, 2019
68e496d
fixed bug with navigation from unsigned positions
idraper Apr 12, 2019
3ca73a4
added generated documentation
idraper Apr 12, 2019
58f6e83
Merge pull request #9 from idraper/style_refactoring
idraper Apr 12, 2019
176bd7f
Merge pull request #10 from idraper/develop
idraper Apr 12, 2019
f264ca9
removed documentation and updated the README to explain the steps to …
idraper Apr 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
918 changes: 918 additions & 0 deletions community/c++-algo/.gitignore

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions community/c++-algo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cmake_minimum_required (VERSION 2.6)
project (StarterAlgo)

set(out_dir ${CMAKE_SOURCE_DIR}/algo-target)
set(CMAKE_CXX_STANDARD 11)

# First for the generic no-config case (e.g. with mingw)
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${out_dir} )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${out_dir}/lib )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${out_dir}/lib )
# Second, for multi-config builds (e.g. msvc)
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${out_dir} )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${out_dir}/lib )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${out_dir}/lib )
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )

set(HEADERS
src/algoStrategy.h
src/algoStrategy.cpp
src/source.cpp
)

add_executable(StarterAlgo ${HEADERS})

target_include_directories (StarterAlgo PRIVATE ${CMAKE_SOURCE_DIR}/include/)

add_subdirectory(${CMAKE_SOURCE_DIR}/include/json11/)
add_subdirectory(${CMAKE_SOURCE_DIR}/include/GameLib/)

target_link_libraries(StarterAlgo json11 GameLib)
119 changes: 119 additions & 0 deletions community/c++-algo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Starter Algo C++

#### NOTE: This project is currently being developed, and is NOT supported by C1's servers yet.
This means you currently cannot upload this algo to their servers, it will not work.
However, if you have a linux OS it is possible compile and upload your compiled version and have it run.
This compilation will not work in the playground.

### Directory Overview

```
community/c++-algo
├───algo-target
│ run.ps1
│ run.sh
├───build
├───documentation
├───include
│ ├───GameLib
│ │ │
│ │ └───src
│ │ algoCore.cpp
│ │ algoCore.h
│ │ customExceptions.h
│ │ enums.h
│ │ gameMap.cpp
│ │ gameMap.h
│ │ gameState.cpp
│ │ gameState.h
│ │ navigation.cpp
│ │ navigation.h
│ │ structs.h
│ │ unit.cpp
│ │ unit.h
│ │ util.cpp
│ │ util.h
│ │
│ └───json11
└───src
algoStrategy.cpp
algoStrategy.h
source.cpp
```


### Creating an algo

For starters, simply modify the `src/algoStrategy.cpp` files. You will be mostly using functions in the `GameState` class.

The `GameState` provides fast and convenient access to the game board, and the ability to perform actions, such as placing a
unit, which will mutate the `GameState` game state, as well as record that action. The GameState can then be used to submit your changes to the engine.

**The standard output is used to communicate with the game engine, and must not be printed to.**
For this reason, debugging must be done with the standard error. The standard error messages are
available on the playground. As an abstraction over this logic, the `Util` method `debugWrite()` prints to the standard error stream.

This project is intentionally modeled after the python-algo to make it familiar to those who are either new to programming in C++ or have been coding with terminal for a while.

### Build script

Since compiling will be different for every user, this is a CMake project to build for multiple enviornments.
This means for whatever enviornemnt you are using, you will need to install CMake (found [here](https://cmake.org/download/)).
In order to compile your algo, create a `build` directory under the `C1GamesStarterKit` directory and then run `cmake`.
Thus, the steps to setup a completely new enviornment would be (in terminal or cmd):
```
C1GamesStarterKit\community\c++-algo> mkdir build
C1GamesStarterKit\community\c++-algo> cd build
C1GamesStarterKit\community\c++-algo\build> cmake ..
```
(the commands are only after the `>`).

This will create a project depending on what system you have avalible.
For example, if you have Visual Studio, it will generate a .sln project inside of `build` and you can then open
the project and build it.
If you are running linux, or something that supports makefiles, then while in the `build` directory you simply run:
```
make
```

In all cases, the target for your executable is inside `c++-algo\algo-target`.

Thus, to run a local game, you would give it the directory `community\c++-algo\algo-target`.

Building this project has been tested using:
- Visual Studio 2017
- Ubuntu 16.04.5 LTS
- Ubuntu 18.04.1 LTS
- MacOS Mojave

### Documentation

Documentation for this starter-kit can be generated using doxygen. The general steps to do so and explanation for their accepted style can be found on [their website](http://www.doxygen.nl/index.html). However, the steps that we took were:

1. Install doxygen (found on their website).
2. Create folder to generate the documentation (`mkdir dox`) and go to it (`cd dox`).
3. Generate the config for doxygen (`doxygen -g dox-config`).
4. Modify the following options found in the dox-config file:
- EXTRACT_ALL = YES
- INPUT = ../ (or the path to the c++-algo code)
- RECURSIVE = YES
- JAVADOC_AUTOBRIEF = YES
- EXCLUDE_PATTERNS = \*/build/* + \*/json11/*
- USE_MDFILE_AS_MAINPAGE = ../README.md (or path to this README)
- STRIP_FROM_PATH (set it equal to the path up to and not including the C1GamesStarterKit) (eg C:/Users/.../)

5. Run doxygen (`doxygen dox-config`).

You can modify the output style further by specifying an html header/footer and css style (see [doxygen documentation](http://www.doxygen.nl/manual/customize.html).

### Contributing

This is a community made and supported algo. If you'd like to contribute a new feature
just reach out to me (@Isaac) on the [C1 forums](https://forum.c1games.com/) or submit a pull request with your changes.

Feel free to submit a Pull Request for any bugs or new features, but please try and follow the style of the rest of the project.
4 changes: 4 additions & 0 deletions community/c++-algo/algo-target/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$scriptPath = Split-Path -parent $PSCommandPath;
$algoPath = "$scriptPath\StarterAlgo.exe"

Invoke-Expression $algoPath
3 changes: 3 additions & 0 deletions community/c++-algo/algo-target/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
"$DIR/StarterAlgo"
26 changes: 26 additions & 0 deletions community/c++-algo/include/GameLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required (VERSION 2.6)
project (GameLib)

set(HEADERS
src/customExceptions.h
src/structs.h
src/enums.h
src/util.h
src/util.cpp
src/algoCore.h
src/algoCore.cpp
src/gameState.h
src/gameState.cpp
src/gameMap.h
src/gameMap.cpp
src/unit.h
src/unit.cpp
src/navigation.h
src/navigation.cpp
)

add_library(GameLib ${HEADERS})

target_include_directories (GameLib PRIVATE ${CMAKE_SOURCE_DIR}/include/)

target_link_libraries(GameLib json11)
8 changes: 8 additions & 0 deletions community/c++-algo/include/GameLib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### GameLib Library

This is a small, simple library to make interfacing with the Terminal engine easier.
It is very heavily modeled after the `python-algo` gamelib project.

It contains classes to make it easier to submit your turns and get the information from the terminal engine.

It also contains a `GameState` class which contains functions to allow you to create theoretical game states and to test strategies before you submit them to the engine. This includes things like pathfinding and predicting future resources.
115 changes: 115 additions & 0 deletions community/c++-algo/include/GameLib/src/algoCore.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
Description: The default object to override for your strategy.
Last Modified: 08 Apr 2019
Author: Isaac Draper
*/

#include "algoCore.h"

namespace terminal {

using json11::Json;

/// Basic constructor for algoCore.
AlgoCore::AlgoCore() {
endOfGame = false;
}

/// A function that runs at the start of every game.
/// Override this to perform initial setup at the start of the game, based on the configuration.
/// @param configuration A Json object containing information about the game.
void AlgoCore::onGameStart(Json configuration) {
config = configuration;
}

/// Called when the engine expects input from the algo.
/// It is called every turn and is passed a Json object containing
/// the current game state, which can be used to initialize a new gameState object.
/// @param gameState A Json object containing the current game state.
void AlgoCore::onTurn(Json gameState) {
AlgoCore::submitDefaultTurn();
}

/// Submits a turn that does nothing.
void AlgoCore::submitDefaultTurn() const {
Util::sendCommand("[]");
Util::sendCommand("[]");
}

/// Starts the main loop of the program.
/// This will continue until it gets the end of state signal from the engine.
/// If there is some error, it will never exit since it will continue
/// to wait until it recieves input from the engine.
/// If this happens it must be killed manually.
void AlgoCore::start() {
Util::debugWrite("Starting C++ Starter Algo");

while (true) {
try {
Json gameState = Util::getCommand();

if (gameState["turnInfo"] == nullptr) {
// Here we know it is the first turn, and the gameState object
// is information about the game, not an actual game state.
// Thus, we run the setup for the game.

onGameStart(gameState);
}
else {
int stateType = gameState["turnInfo"].array_items().at(0).int_value();

// We now make decisions based on what turn state it is.
switch (stateType) {
case 0: {
// This is when the engine expects to recieve what we are
// building for this turn.
// So we run the onTurn function.

onTurn(gameState);
break;
}
case 1: {
// This is a single frame from the engine.
// If you want to get information from the game every frame,
// you can create function to do that here.

break;
}
case 2: {
// This indicates that the game has ended.
// Since break simply takes us out of the switch,
// we use a variable to quite the while loop.

Util::debugWrite("GOT END OF STATE");
endOfGame = true;
break;
}
default: {
// This means we got an unexpected string.
// This technically should never happen since it would
// be caught by the Json parser.

Util::debugWrite("Unexpected state recieved: " + std::to_string(stateType));
break;
}
}

if (endOfGame) {
break;
}
}
}
catch (UtilException e) {
Util::debugWrite(e.what());
continue;
}
}
}

/// This returns a string representation of the AlgoCore object.
/// @return A string to represent this object.
std::string AlgoCore::toString() const {
return "AlgoCore";
}

}
54 changes: 54 additions & 0 deletions community/c++-algo/include/GameLib/src/algoCore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Description: This contains the core components necessary for an algo to run.
Last Modified: 08 Apr 2019
Author: Isaac Draper
*/

#ifndef ALGO_CORE_H
#define ALGO_CORE_H

#include <iostream>
#include <string>

#include "json11/json11.hpp"
#include "customExceptions.h"
#include "util.h"

namespace terminal {

using json11::Json;

/// This is the super class to contain the basic essentials.
/// You should inherit from this class when developing your strategy.
class AlgoCore {
public:
// Functions
AlgoCore();
virtual void start();
virtual std::string toString() const;

protected:
// Functions
virtual void onGameStart(Json configuration);
virtual void onTurn(Json gameState);
void submitDefaultTurn() const;

// Members
Json config; ///< Holds information about the game.

private:
// Members
bool endOfGame; ///< Keeps track of whether the game has ended.

};

/// This sends a representation of the AlgoCore object to a stream.
/// @return The stream passed to the function.
inline std::ostream& operator<<(std::ostream& os, AlgoCore const& algoCore) {
os << algoCore.toString();
return os;
}

}

#endif
Loading