Initial commit on develop branch
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
#include "../Database/GameHistoryManager.h"
|
||||
#include "IntSqrt.h"
|
||||
#include "GetSavedBoardSize.h"
|
||||
#include <string>
|
||||
|
||||
int getSavedBoardSize(std::string board)
|
||||
{
|
||||
int elementCount = getSavedBoardElementCount(board);
|
||||
return intSqrt(elementCount);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
int getSavedBoardSize(std::string board);
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "IntSqrt.h"
|
||||
|
||||
int intSqrt(int number)
|
||||
{
|
||||
for (int i = 1; i < 100000000; i++)
|
||||
{
|
||||
if (i * i == number) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
int intSqrt(int);
|
||||
@@ -0,0 +1,73 @@
|
||||
#include <string>
|
||||
#include "IntToStr.h"
|
||||
|
||||
|
||||
|
||||
char getChar(int digit);
|
||||
int getDigitsCount(int number);
|
||||
|
||||
|
||||
|
||||
std::string intToStr(int number)
|
||||
{
|
||||
int numberLen = getDigitsCount(number);
|
||||
|
||||
char result[numberLen];
|
||||
|
||||
for (int i = numberLen - 1; i >= 0; i--)
|
||||
{
|
||||
result[i] = getChar(number % 10);
|
||||
number /= 10;
|
||||
}
|
||||
|
||||
std::string resultStr = "";
|
||||
|
||||
for (int i = 0; i < numberLen; i++)
|
||||
{
|
||||
resultStr += result[i];
|
||||
}
|
||||
|
||||
return resultStr;
|
||||
}
|
||||
|
||||
char getChar(int digit)
|
||||
{
|
||||
switch (digit)
|
||||
{
|
||||
case 0:
|
||||
return '0';
|
||||
case 1:
|
||||
return '1';
|
||||
case 2:
|
||||
return '2';
|
||||
case 3:
|
||||
return '3';
|
||||
case 4:
|
||||
return '4';
|
||||
case 5:
|
||||
return '5';
|
||||
case 6:
|
||||
return '6';
|
||||
case 7:
|
||||
return '7';
|
||||
case 8:
|
||||
return '8';
|
||||
case 9:
|
||||
return '9';
|
||||
}
|
||||
}
|
||||
|
||||
int getDigitsCount(int number)
|
||||
{
|
||||
if (number == 0) return 1;
|
||||
|
||||
int count = 0;
|
||||
|
||||
while(number != 0)
|
||||
{
|
||||
number /= 10;
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string intToStr(int);
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <iostream>
|
||||
#include "Print.h"
|
||||
|
||||
void print(std::string subject, int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++) std::cout << subject;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
void print(std::string subject, int count);
|
||||
@@ -0,0 +1,51 @@
|
||||
#include <string>
|
||||
#include "StrToInt.h"
|
||||
|
||||
|
||||
|
||||
int getNumber(char digit);
|
||||
|
||||
|
||||
|
||||
// turns a string containing digits into a integer
|
||||
int strToInt(std::string number)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
while (number != "")
|
||||
{
|
||||
result = result*10 + getNumber((char) number[0]);
|
||||
number = number.substr(1, number.size());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int getNumber(char digit)
|
||||
{
|
||||
switch (digit)
|
||||
{
|
||||
case '0':
|
||||
return 0;
|
||||
case '1':
|
||||
return 1;
|
||||
case '2':
|
||||
return 2;
|
||||
case '3':
|
||||
return 3;
|
||||
case '4':
|
||||
return 4;
|
||||
case '5':
|
||||
return 5;
|
||||
case '6':
|
||||
return 6;
|
||||
case '7':
|
||||
return 7;
|
||||
case '8':
|
||||
return 8;
|
||||
case '9':
|
||||
return 9;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
int strToInt(std::string number);
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <string>
|
||||
|
||||
char strToSymbol(std::string character)
|
||||
{
|
||||
if (character == "W")
|
||||
{
|
||||
return 'W';
|
||||
}
|
||||
else if (character == "B")
|
||||
{
|
||||
return 'B';
|
||||
}
|
||||
else if (character == ".")
|
||||
{
|
||||
return '.';
|
||||
}
|
||||
else if (character == "X")
|
||||
{
|
||||
return 'X';
|
||||
}
|
||||
else if (character == "O")
|
||||
{
|
||||
return 'O';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
char strToSymbol(std::string character);
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <string>
|
||||
|
||||
std::string symbolToStr(char character)
|
||||
{
|
||||
if (character == 'W')
|
||||
{
|
||||
return "W";
|
||||
}
|
||||
else if (character == 'B')
|
||||
{
|
||||
return "B";
|
||||
}
|
||||
else if (character == '.')
|
||||
{
|
||||
return ".";
|
||||
}
|
||||
else if (character == 'X')
|
||||
{
|
||||
return "X";
|
||||
}
|
||||
else if (character == 'O')
|
||||
{
|
||||
return "O";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string symbolToStr(char);
|
||||
@@ -0,0 +1,129 @@
|
||||
#include "../Database/GameHistoryManager.h"
|
||||
#include "../Utilities/IntToStr.h"
|
||||
#include "../Structures/Board.h"
|
||||
#include "../Structures/Player.h"
|
||||
#include "../Structures/Bot.h"
|
||||
#include "../Structures/SinglePlayerGame.h"
|
||||
#include "../Structures/MultiPlayerGame.h"
|
||||
#include "GetSavedBoardSize.h"
|
||||
#include "Print.h"
|
||||
#include "outputDecoratedSavedGame.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
void outputDecoratedSavedSinglePlayerGame(std::string savedGame);
|
||||
void outputDecoratedSavedMultiPlayerGame(std::string savedGame);
|
||||
|
||||
|
||||
|
||||
void outputDecoratedSavedGame(std::string savedGame)
|
||||
{
|
||||
std::string gameMode = getProperty(2, savedGame);
|
||||
|
||||
if (gameMode == "1Player")
|
||||
{
|
||||
return outputDecoratedSavedSinglePlayerGame(savedGame);
|
||||
}
|
||||
else
|
||||
{
|
||||
return outputDecoratedSavedMultiPlayerGame(savedGame);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void outputDecoratedSavedSinglePlayerGame(std::string savedGame)
|
||||
{
|
||||
int id = getGameId(savedGame);
|
||||
Board board = *(getSinglePlayerGame(id).GameBoard);
|
||||
Player player = *(getSinglePlayerGame(id).Player1);
|
||||
Bot bot = *(getSinglePlayerGame(id).GameBot);
|
||||
char CurrentTurnColor = getSinglePlayerGame(id).CurrentTurnColor;
|
||||
int Winner = getSinglePlayerGame(id).Winner;
|
||||
|
||||
SinglePlayerGame game {&board, &player, &bot, CurrentTurnColor};
|
||||
game.id = id;
|
||||
game.Winner = Winner;
|
||||
game.mode = "1Player";
|
||||
game.GameBoard -> CursorX = -1;
|
||||
game.GameBoard -> CursorY = -1;
|
||||
|
||||
|
||||
std::cout << "{\n id = " << intToStr(game.id) << "\n";
|
||||
|
||||
std::cout << " game board = { \n";
|
||||
game.GameBoard -> display();
|
||||
|
||||
std::cout << " mode = single player\n";
|
||||
|
||||
std::cout << " Player = {\n"
|
||||
<< " name = " << game.Player1 -> name << std::endl
|
||||
<< " color = " << (game.Player1 -> color == 'W' ? "White":"Black") << std::endl
|
||||
<< " }\n";
|
||||
|
||||
|
||||
int botDifficulty = game.GameBot -> difficulty;
|
||||
std::string difficultyToOutput = (
|
||||
botDifficulty == 1 ?
|
||||
"easy" : botDifficulty == 2 ?
|
||||
"medium" : "hard"
|
||||
);
|
||||
std::cout << " Bot = {\n"
|
||||
<< " difficulty = " << difficultyToOutput << std::endl
|
||||
<< " }\n";
|
||||
|
||||
int winner = game.Winner;
|
||||
std::string winnerToOutput = (
|
||||
winner == 0 ?
|
||||
"The game is unfinished" : winner == 1 ?
|
||||
"Player has won this game" : winner == 2 ?
|
||||
"Bot has won this game" : "The game resulted in a draw"
|
||||
);
|
||||
std::cout << " " << winnerToOutput << "\n}\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
void outputDecoratedSavedMultiPlayerGame(std::string savedGame)
|
||||
{
|
||||
int id = getGameId(savedGame);
|
||||
Board board = *(getMultiPlayerGame(id).GameBoard);
|
||||
Player player1 = *(getMultiPlayerGame(id).Player1);
|
||||
Player player2 = *(getMultiPlayerGame(id).Player2);
|
||||
char CurrentTurnColor = getMultiPlayerGame(id).CurrentTurnColor;
|
||||
int Winner = getMultiPlayerGame(id).Winner;
|
||||
|
||||
MultiPlayerGame game {&board, &player1, &player2, CurrentTurnColor};
|
||||
game.id = id;
|
||||
game.Winner = Winner;
|
||||
game.mode = "2Player";
|
||||
game.GameBoard -> CursorX = -1;
|
||||
game.GameBoard -> CursorY = -1;
|
||||
|
||||
std::cout << "{\n id = " << intToStr(game.id) << "\n";
|
||||
|
||||
std::cout << " game board = { \n";
|
||||
game.GameBoard -> display();
|
||||
|
||||
std::cout << " mode = Multiplayer\n";
|
||||
|
||||
std::cout << " Player1 = {\n"
|
||||
<< " name = " << game.Player1 -> name << std::endl
|
||||
<< " color = " << (game.Player1 -> color == 'W' ? "White":"Black") << std::endl
|
||||
<< " }\n";
|
||||
|
||||
std::cout << " Player2 = {\n"
|
||||
<< " name = " << game.Player2 -> name << std::endl
|
||||
<< " color = " << (game.Player2 -> color == 'W' ? "White":"Black") << std::endl
|
||||
<< " }\n";
|
||||
|
||||
int winner = game.Winner;
|
||||
std::string winnerToOutput = (
|
||||
winner == 0 ?
|
||||
"The game is unfinished" : winner == 1 ?
|
||||
"Player1 has won this game" : winner == 2 ?
|
||||
"Player2 has won this game" : "The game resulted in a draw"
|
||||
);
|
||||
std::cout << " " << winnerToOutput << "\n}\n";
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
void outputDecoratedSavedGame(std::string savedGame);
|
||||
Reference in New Issue
Block a user