diff --git a/bin/app/data/ApplicationSettings_for_package.xml b/bin/app/data/ApplicationSettings_for_package.xml new file mode 100644 index 00000000..182f87f5 --- /dev/null +++ b/bin/app/data/ApplicationSettings_for_package.xml @@ -0,0 +1,9 @@ + + + + + ./data/projects/tutorial/tutorial.xml + ./data/projects/tictactoe/tictactoe.xml + + + diff --git a/bin/app/data/projects/tictactoe/src/artificial_player.cpp b/bin/app/data/projects/tictactoe/src/artificial_player.cpp new file mode 100644 index 00000000..a6457f73 --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/artificial_player.cpp @@ -0,0 +1,67 @@ +#include "artificial_player.h" + +ArtificialPlayer::ArtificialPlayer( Field::Token token, const char* name ) + : Player( token, name ) { +} + +ArtificialPlayer::~ArtificialPlayer() { +} + +Field::Move ArtificialPlayer::Turn( const Field& field ) const { + Field fakeField = field.Clone(); + Node node = MinMax( fakeField, token_ ); + return node.move; +} + +ArtificialPlayer::Node ArtificialPlayer::MinMax( Field& field, Field::Token token ) const { + Node node; + node.value = -10000; + + Field::Move move; + int sameMove; + + for ( int i = 0; i < 3; i++ ) { + move.row = i; + + for ( int j = 0; j < 3; j++ ) { + move.col = j; + + if ( !field.IsEmpty( move ) ) { + continue; + } + + field.MakeMove( move, token ); + + int turnValue = Evaluate( field, token ); + if ( !turnValue && !field.IsFull() ) { + turnValue = -MinMax( field, Field::Opponent( token ) ).value; + } + + field.ClearMove( move ); + + if ( turnValue > node.value ) { + node.move = move; + node.value = turnValue; + sameMove = 1; + } else if ( turnValue == node.value ) { + sameMove++; + if ( 1 % sameMove == 0 ) { + node.move = move; + } + } + } + } + + return node; +} + +int ArtificialPlayer::Evaluate( const Field& field, Field::Token token ) const { + if ( field.SameInRow( token, 3 ) ) { + return 2; + } else if ( field.SameInRow( Field::Opponent( token ), 2 ) ) { + return -1; + } else if ( field.SameInRow( token, 2 ) > 1 ) { + return 1; + } + return 0; +} diff --git a/bin/app/data/projects/tictactoe/src/artificial_player.h b/bin/app/data/projects/tictactoe/src/artificial_player.h new file mode 100644 index 00000000..8b564edd --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/artificial_player.h @@ -0,0 +1,24 @@ +#ifndef _ARTIFICIAL_PLAYER_ +#define _ARTIFICIAL_PLAYER_ + +#include "player.h" + +class ArtificialPlayer : public Player { +public: + ArtificialPlayer( Field::Token token, const char* name ); + virtual ~ArtificialPlayer(); + + virtual Field::Move Turn( const Field& field ) const; + +private: + struct Node { + Field::Move move; + int value; + }; + + Node MinMax( Field& field, Field::Token token ) const; + + int Evaluate( const Field& field, Field::Token token ) const; +}; + +#endif // _ARTIFICIAL_PLAYER_ diff --git a/bin/app/data/projects/tictactoe/src/field.cpp b/bin/app/data/projects/tictactoe/src/field.cpp new file mode 100644 index 00000000..313ed89a --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/field.cpp @@ -0,0 +1,126 @@ +#include "field.h" + +#include "io.h" + +Field::Token Field::Opponent( Token token ) { + if ( token == PlayerA ) { + return PlayerB; + } else if (token == PlayerB){ + return PlayerA; + } else { + return None; + } +} + +Field::Field() + : left_( 9 ) { + grid_ = new Token* [3]; + for ( int i = 0; i < 3 ; i++ ) { + grid_[i] = new Token[3]; + } +} + +Field::~Field() { + for ( int i = 0; i < 3; i++ ) { + delete grid_[i]; + } + delete [] grid_; +} + +Field Field::Clone() const { + Field field; + for ( int i = 0; i < 3; i++ ) { + for ( int j = 0; j < 3; j++ ) { + field.grid_[i][j] = grid_[i][j]; + } + } + field.left_ = left_; + return field; +} + +void Field::Clear() { + for ( int i = 0; i < 3; i++ ) { + for ( int j = 0; j < 3; j++ ) { + grid_[i][j] = None; + } + } + left_ = 9; +} + +void Field::Show() const { + io::stringOut(" 1 2 3\n"); + for ( int row = 0; row < 3; row++ ) { + io::numberOut(row + 1); + io::stringOut(" "); + + for ( int col = 0; col < 3; col++ ) { + if ( grid_[row][col] == PlayerA ) { + io::stringOut(" X "); + } else if ( grid_[row][col] == PlayerB ) { + io::stringOut(" O "); + } else { + io::stringOut(" "); + } + + if ( col < 2 ) { + io::stringOut("|"); + } + } + + if ( row < 2 ) { + io::stringOut("\n -----------\n"); + } + } + io::stringOut("\n\n"); +} + +int Field::SameInRow( Token token, int amount ) const { + int sum = amount * token; + int count = 0; + + for ( int i = 0; i < 3; i++ ) { + if ( grid_[i][0] + grid_[i][1] + grid_[i][2] == sum ) { + count++; + } else if ( grid_[0][i] + grid_[1][i] + grid_[2][i] == sum ) { + count++; + } + } + + if ( grid_[0][0] + grid_[1][1] + grid_[2][2] == sum ) { + count++; + } else if ( grid_[2][0] + grid_[1][1] + grid_[0][2] == sum ) { + count++; + } + + return count; +} + +bool Field::InRange( const Move& move ) const { + return move.row >= 0 && move.row < 3 && move.col >= 0 && move.col < 3; +} + +bool Field::IsEmpty( const Move& move ) const { + return grid_[move.row][move.col] == None; +} + +bool Field::IsFull() const { + return left_ == 0; +} + +void Field::MakeMove( const Move& move, Token token ) { + if ( !InRange( move ) || !IsEmpty( move ) || token == None || !left_ ) { + return; + } + + grid_[move.row][move.col] = token; + left_--; +} + +void Field::ClearMove( const Move& move ) { + if ( !InRange( move ) || !IsEmpty( move ) || left_ == 9 ) { + return; + } + + grid_[move.row][move.col] = None; + left_++; +} diff --git a/bin/app/data/projects/tictactoe/src/field.h b/bin/app/data/projects/tictactoe/src/field.h new file mode 100644 index 00000000..ef3201e8 --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/field.h @@ -0,0 +1,41 @@ +#ifndef _FIELD_ +#define _FIELD_ + +class Field { +public: + enum Token { + None = 0, + PlayerA = 1, + PlayerB = 4 + }; + + static Token Opponent( Token token ); + + struct Move { + int row; + int col; + }; + + Field(); + ~Field(); + + Field Clone() const; + void Clear(); + + void Show() const; + + int SameInRow( Token token, int amount ) const; + + bool InRange( const Move& move ) const; + bool IsEmpty( const Move& move ) const; + bool IsFull() const; + + void MakeMove( const Move& move, Token token ); + void ClearMove( const Move& move ); + +private: + Token** grid_; + int left_; +}; + +#endif // _FIELD_ diff --git a/bin/app/data/projects/tictactoe/src/human_player.cpp b/bin/app/data/projects/tictactoe/src/human_player.cpp new file mode 100644 index 00000000..4357d897 --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/human_player.cpp @@ -0,0 +1,49 @@ +#include "human_player.h" + +#include "io.h" + +HumanPlayer::HumanPlayer( Field::Token token, const char* name ) + : Player( token, name ) { +} + +HumanPlayer::~HumanPlayer() { +} + +Field::Move HumanPlayer::Turn( const Field& field ) const { + Field::Move move; + io::stringOut(name_); + io::stringOut("\n"); + + do { + move = Input(); + move.row -= 1; + move.col -= 1; + } while ( !Check( field, move ) ); + return move; +} + +Field::Move HumanPlayer::Input() const { + Field::Move move; + move.row = -1; + move.col = -1; + + io::stringOut("Insert row: "); + move.row = io::numberIn(); + + io::stringOut("Insert column: "); + move.col = io::numberIn(); + + io::stringOut("\n"); + return move; +} + +bool HumanPlayer::Check( const Field& field, const Field::Move& move ) const { + if ( !field.InRange( move ) ) { + io::stringOut("Wrong input!\n"); + return false; + } else if ( !field.IsEmpty( move ) ) { + io::stringOut("Is occupied!\n"); + return false; + } + return true; +} diff --git a/bin/app/data/projects/tictactoe/src/human_player.h b/bin/app/data/projects/tictactoe/src/human_player.h new file mode 100644 index 00000000..a2039fa3 --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/human_player.h @@ -0,0 +1,19 @@ +#ifndef _HUMAN_PLAYER_ +#define _HUMAN_PLAYER_ + +#include "player.h" + +class HumanPlayer : public Player { +public: + HumanPlayer( Field::Token token, const char* name ); + virtual ~HumanPlayer(); + + virtual Field::Move Turn( const Field& field ) const; + +private: + Field::Move Input() const; + + bool Check( const Field& field, const Field::Move& move ) const; +}; + +#endif // _HUMAN_PLAYER_ diff --git a/bin/app/data/projects/tictactoe/src/io.cpp b/bin/app/data/projects/tictactoe/src/io.cpp new file mode 100644 index 00000000..2b9511cc --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/io.cpp @@ -0,0 +1,23 @@ +#include "io.h" + +// #include +// #include +// #include + +int io::numberIn() { + // std::string input; + // getline( std::cin, input ); + // std::stringstream stream( input ); + + int number; + // stream >> number; + return number; +} + +void io::numberOut(int num) { + // std::cout << num; +} + +void io::stringOut(const char* str) { + // std::cout << str; +} diff --git a/bin/app/data/projects/tictactoe/src/io.h b/bin/app/data/projects/tictactoe/src/io.h new file mode 100644 index 00000000..bacfe58e --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/io.h @@ -0,0 +1,13 @@ +#ifndef _IO_ +#define _IO_ + +namespace io { + + int numberIn(); + void numberOut(int num); + + void stringOut(const char* str); + +} + +#endif // _IO_ diff --git a/bin/app/data/projects/tictactoe/src/main.cpp b/bin/app/data/projects/tictactoe/src/main.cpp new file mode 100644 index 00000000..8d15ea5f --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/main.cpp @@ -0,0 +1,11 @@ +#include "tictactoe.h" + +int main() { + TicTacToe tictactoe; + + while ( tictactoe.Start() ) { + tictactoe.Run(); + } + + return 0; +} diff --git a/bin/app/data/projects/tictactoe/src/player.cpp b/bin/app/data/projects/tictactoe/src/player.cpp new file mode 100644 index 00000000..a1b3694c --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/player.cpp @@ -0,0 +1,19 @@ +#include "player.h" + +Player::Player( Field::Token token, const char* name ) + : token_( token ) + , name_( name ) { +} + +Player::~Player() { +} + +const Field::Token& Player::getToken() const +{ + return token_; +} + +const char* Player::getName() const +{ + return name_; +} diff --git a/bin/app/data/projects/tictactoe/src/player.h b/bin/app/data/projects/tictactoe/src/player.h new file mode 100644 index 00000000..71a691a4 --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/player.h @@ -0,0 +1,21 @@ +#ifndef _PLAYER_ +#define _PLAYER_ + +#include "field.h" + +class Player { +public: + Player( Field::Token token, const char* name ); + virtual ~Player(); + + virtual Field::Move Turn( const Field& field ) const = 0; + + const Field::Token& getToken() const; + const char* getName() const; + +protected: + const Field::Token token_; + const char* name_; +}; + +#endif // _PLAYER_ diff --git a/bin/app/data/projects/tictactoe/src/tictactoe.cpp b/bin/app/data/projects/tictactoe/src/tictactoe.cpp new file mode 100644 index 00000000..d21a1025 --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/tictactoe.cpp @@ -0,0 +1,85 @@ +#include "tictactoe.h" + +#include "artificial_player.h" +#include "human_player.h" +#include "io.h" + +TicTacToe::TicTacToe() { + players_[0] = 0; + players_[1] = 0; +} + +TicTacToe::~TicTacToe() { + Reset(); +} + +bool TicTacToe::Start() { + Reset(); + io::stringOut("Tic Tac Toe\n\n[1] Human\n[2] Computer\n[3] Quit\n\n"); + + players_[0] = SelectPlayer( Field::PlayerA, "Player A" ); + if ( !players_[0] ) { + return false; + } + + players_[1] = SelectPlayer( Field::PlayerB, "Player B" ); + if ( !players_[1] ) { + return false; + } + + io::stringOut("\n"); + return true; +} + +void TicTacToe::Run() { + field_.Show(); + + int playerIndex = 0; + + for ( int i = 0; i < 9; i++ ) { + Player& player = *players_[playerIndex]; + + field_.MakeMove( player.Turn( field_ ), player.getToken() ); + field_.Show(); + + if ( field_.SameInRow( player.getToken(), 3 ) ) { + io::stringOut(player.getName()); + io::stringOut(" won!\n\n"); + return; + } + + playerIndex = ( playerIndex + 1 ) % 2; + } + + io::stringOut("Game ends in draw!\n\n"); +} + +void TicTacToe::Reset() { + field_.Clear(); + + for ( int i = 0; i < 2; i++ ) { + if ( players_[i] ) { + delete players_[i]; + players_[i] = 0; + } + } +} + +Player* TicTacToe::SelectPlayer( Field::Token token, const char* name ) const { + int selection = 0; + + while ( true ) { + io::stringOut("Choose "); + io::stringOut(name); + io::stringOut(": "); + + selection = io::numberIn(); + + switch ( selection ) { + case 1 : return new HumanPlayer( token, name ); + case 2 : return new ArtificialPlayer( token, name ); + case 3 : return 0; + default : io::stringOut("Wrong input!\n"); + } + } +} diff --git a/bin/app/data/projects/tictactoe/src/tictactoe.h b/bin/app/data/projects/tictactoe/src/tictactoe.h new file mode 100644 index 00000000..6bf279da --- /dev/null +++ b/bin/app/data/projects/tictactoe/src/tictactoe.h @@ -0,0 +1,23 @@ +#ifndef _TIC_TAC_TOE_ +#define _TIC_TAC_TOE_ + +#include "field.h" +#include "player.h" + +class TicTacToe { +public: + TicTacToe(); + ~TicTacToe(); + + bool Start(); + void Run(); + +private: + void Reset(); + Player* SelectPlayer( Field::Token token, const char* name ) const; + + Player* players_[2]; + Field field_; +}; + +#endif // _TIC_TAC_TOE_ diff --git a/bin/app/data/projects/tictactoe/tictactoe.xml b/bin/app/data/projects/tictactoe/tictactoe.xml new file mode 100644 index 00000000..ff5af2b5 --- /dev/null +++ b/bin/app/data/projects/tictactoe/tictactoe.xml @@ -0,0 +1,12 @@ + + + + + .h + .cpp + + + ./src + + + \ No newline at end of file diff --git a/ide_plugins/sublime_text/CoatiCommunicator/CoatiCommunicator.py b/ide_plugins/sublime_text/CoatiPlugin/CoatiPlugin.py similarity index 94% rename from ide_plugins/sublime_text/CoatiCommunicator/CoatiCommunicator.py rename to ide_plugins/sublime_text/CoatiPlugin/CoatiPlugin.py index 481519db..786b9a15 100644 --- a/ide_plugins/sublime_text/CoatiCommunicator/CoatiCommunicator.py +++ b/ide_plugins/sublime_text/CoatiPlugin/CoatiPlugin.py @@ -52,7 +52,7 @@ class ServerStartupListener(sublime_plugin.EventListener): if (not self.running): self.running = True - settings = sublime.load_settings('CoatiCommunicator.sublime-settings') + settings = sublime.load_settings('CoatiPlugin.sublime-settings') host_ip = settings.get('host_ip') coati_to_plugin_port = settings.get('coati_to_sublime_port') @@ -74,7 +74,7 @@ class SetActiveTokenCommand(sublime_plugin.TextCommand): text = "setActiveToken" + MESSAGE_SPLIT_STRING + filePath + MESSAGE_SPLIT_STRING + str(row) + MESSAGE_SPLIT_STRING + str(col) + "" data = text.encode() - settings = sublime.load_settings('CoatiCommunicator.sublime-settings') + settings = sublime.load_settings('CoatiPlugin.sublime-settings') host_ip = settings.get('host_ip') plugin_to_coati_port = settings.get('sublime_to_coati_port') diff --git a/ide_plugins/sublime_text/CoatiCommunicator/CoatiCommunicator.sublime-settings b/ide_plugins/sublime_text/CoatiPlugin/CoatiPlugin.sublime-settings similarity index 100% rename from ide_plugins/sublime_text/CoatiCommunicator/CoatiCommunicator.sublime-settings rename to ide_plugins/sublime_text/CoatiPlugin/CoatiPlugin.sublime-settings diff --git a/ide_plugins/sublime_text/CoatiCommunicator/Context.sublime-menu b/ide_plugins/sublime_text/CoatiPlugin/Context.sublime-menu similarity index 100% rename from ide_plugins/sublime_text/CoatiCommunicator/Context.sublime-menu rename to ide_plugins/sublime_text/CoatiPlugin/Context.sublime-menu diff --git a/ide_plugins/sublime_text/readme.txt b/ide_plugins/sublime_text/readme.txt index 3a4ad976..19be79f5 100644 --- a/ide_plugins/sublime_text/readme.txt +++ b/ide_plugins/sublime_text/readme.txt @@ -1,5 +1,5 @@ How to Install: -Just copy and past this "CoatiCommunicator" folder into your Packages folder of Sublime Text. (You can find +Just copy and past this "CoatiPlugin" folder into your Packages folder of Sublime Text. (You can find that folder from within Sublime via the menu: Preferences -> Browse Packages...). Restart Sublime before starting to use the plugin. diff --git a/ide_plugins/vs/coati_plugin_vs_2012.vsix b/ide_plugins/vs/coati_plugin_vs_2012.vsix new file mode 100644 index 00000000..c1b9a0bb Binary files /dev/null and b/ide_plugins/vs/coati_plugin_vs_2012.vsix differ diff --git a/ide_plugins/vs/coati_plugin_vs_2013.vsix b/ide_plugins/vs/coati_plugin_vs_2013.vsix new file mode 100644 index 00000000..c5924965 Binary files /dev/null and b/ide_plugins/vs/coati_plugin_vs_2013.vsix differ diff --git a/ide_plugins/vs/coati_plugin_vs_2015.vsix b/ide_plugins/vs/coati_plugin_vs_2015.vsix new file mode 100644 index 00000000..65b4dbfe Binary files /dev/null and b/ide_plugins/vs/coati_plugin_vs_2015.vsix differ diff --git a/script/packaging_windows.sh b/script/packaging_windows.sh new file mode 100644 index 00000000..51fe73be --- /dev/null +++ b/script/packaging_windows.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +ABORT="\033[31mAbort:\033[00m" +SUCCESS="\033[32mSuccess:\033[00m" +INFO="\033[33mInfo:\033[00m" + +read -r -p "Is your current release build up to date? [y/N] " response +case $response in + [yY][eE][sS]|[yY]) + ;; + *) + echo -e $ABORT "Aborting the creation of a release package." + exit 1 + ;; +esac + +ORIGINAL_PATH_TO_SCRIPT="${0}" +CLEANED_PATH_TO_SCRIPT="${ORIGINAL_PATH_TO_SCRIPT//\\//}" +BASE_DIR=`dirname "$CLEANED_PATH_TO_SCRIPT"` + +cd $BASE_DIR/.. + +VERSION_STRING=$(git describe) +VERSION_STRING="${VERSION_STRING//-/_}" +VERSION_STRING="${VERSION_STRING//./_}" +VERSION_STRING="${VERSION_STRING%_*}" + +PACKAGE_NAME=Coati_${VERSION_STRING}_windows + +echo -e $INFO Creating Package with Name: $PACKAGE_NAME + +PACKAGE_DIR=release/$PACKAGE_NAME + + +echo -e $INFO Creating Folders +rm -rf $PACKAGE_DIR +mkdir -p $PACKAGE_DIR + +mkdir -p $PACKAGE_DIR/data/color_schemes/ +cp -u -r bin/app/data/color_schemes/* $PACKAGE_DIR/data/color_schemes/ +mkdir -p $PACKAGE_DIR/data/fonts/ +cp -u -r bin/app/data/fonts/* $PACKAGE_DIR/data/fonts/ +mkdir -p $PACKAGE_DIR/data/gui/ +cp -u -r bin/app/data/gui/* $PACKAGE_DIR/data/gui/ +mkdir -p $PACKAGE_DIR/data/log/ +mkdir -p $PACKAGE_DIR/data/projects/tutorial/src/ +cp -u -r bin/app/data/projects/tutorial/src/* $PACKAGE_DIR/data/projects/tutorial/src/ +cp -u -r bin/app/data/projects/tutorial/tutorial.xml $PACKAGE_DIR/data/projects/tutorial/ +mkdir -p $PACKAGE_DIR/data/projects/tictactoe/src/ +cp -u -r bin/app/data/projects/tictactoe/src/* $PACKAGE_DIR/data/projects/tictactoe/src/ +cp -u -r bin/app/data/projects/tictactoe/tictactoe.xml $PACKAGE_DIR/data/projects/tictactoe/ + +cp -u -r bin/app/data/ApplicationSettings_for_package.xml $PACKAGE_DIR/data/ApplicationSettings.xml +cp -u -r bin/app/data/window_settings.ini $PACKAGE_DIR/data/ + +mkdir -p $PACKAGE_DIR/plugins/visual_studio/ +cp -u -r ide_plugins/vs/coati_plugin_vs_2012.vsix $PACKAGE_DIR/plugins/visual_studio/ +cp -u -r ide_plugins/vs/coati_plugin_vs_2013.vsix $PACKAGE_DIR/plugins/visual_studio/ +cp -u -r ide_plugins/vs/coati_plugin_vs_2015.vsix $PACKAGE_DIR/plugins/visual_studio/ +mkdir -p $PACKAGE_DIR/plugins/sublime_text/ +cp -u -r ide_plugins/sublime_text/* $PACKAGE_DIR/plugins/sublime_text/ + +cp -u -r web/coati_manual.pdf $PACKAGE_DIR/ +cp -u -r bin/app/Release/Coati.exe $PACKAGE_DIR/ +cp -u -r setup/dynamic_libraries/windows/app/Release/* $PACKAGE_DIR/ + + +echo -e $INFO Obfuscation Executable +#upx --brute $PACKAGE_DIR/Coati.exe + +echo -e $INFO Packaging Coati +cd ./release/ +winrar a -afzip $PACKAGE_NAME.zip $PACKAGE_NAME +cd ../ + + +echo -e $INFO Cleaning up +rm -rf $PACKAGE_DIR + +echo -e $SUCCESS Packaging Complete! \ No newline at end of file diff --git a/setup/dynamic_libraries/windows/app/Release/platforms/qwindows.dll b/setup/dynamic_libraries/windows/app/Release/platforms/qwindows.dll new file mode 100644 index 00000000..b68a9cf2 Binary files /dev/null and b/setup/dynamic_libraries/windows/app/Release/platforms/qwindows.dll differ