Initial commit
This commit is contained in:
commit
4f4397b3e1
48 changed files with 2002 additions and 0 deletions
38
NimGame/game/nimgame/NimGame.h
Normal file
38
NimGame/game/nimgame/NimGame.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// Created by JoachimWagner on 10.03.2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "../AbstractGame.h"
|
||||
#include "../../io/Writer.h"
|
||||
#include "../player/Player.h"
|
||||
|
||||
namespace atlas::game::nimgame {
|
||||
|
||||
class NimGame: public AbstractGame<int, int> {
|
||||
|
||||
|
||||
public:
|
||||
explicit NimGame(io::Writer &writer) : AbstractGame(writer) {
|
||||
setBoard(23);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
auto updateBoard()-> void override{ setBoard(getBoard()- getTurn());}
|
||||
|
||||
auto isGameOver()->bool override{ // Operation
|
||||
return getBoard() < 1 || getPlayers().empty();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto isTurnValid() const -> bool override { return getTurn() >= 1 && getTurn() <= 3; }
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
17
NimGame/game/nimgame/player/AbstractNimGamePlayer.h
Normal file
17
NimGame/game/nimgame/player/AbstractNimGamePlayer.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// Created by JoachimWagner on 11.03.2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "../../player/AbstractPlayer.h"
|
||||
namespace atlas::game::nimgame::player {
|
||||
|
||||
class AbstractNimGamePlayer: public atlas::game::player::AbstractPlayer<int, int>{
|
||||
|
||||
public:
|
||||
explicit AbstractNimGamePlayer(const std::string &name) : AbstractPlayer(name) {}
|
||||
};
|
||||
|
||||
}
|
||||
22
NimGame/game/nimgame/player/ComputerPlayer.h
Normal file
22
NimGame/game/nimgame/player/ComputerPlayer.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// Created by JoachimWagner on 11.03.2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include "AbstractNimGamePlayer.h"
|
||||
namespace atlas::game::nimgame::player {
|
||||
class ComputerPlayer :public AbstractNimGamePlayer{
|
||||
static inline int turns[] = {3,1,1,2};
|
||||
public:
|
||||
explicit ComputerPlayer(const std::string &name) : AbstractNimGamePlayer(name) {}
|
||||
|
||||
auto doTurn(const int &stones) const -> int override {
|
||||
|
||||
const int turn = turns[stones % 4];
|
||||
std::cout << "Computer nimmt " << turn << " Steine." << std::endl;
|
||||
return turn;
|
||||
}
|
||||
};
|
||||
}
|
||||
26
NimGame/game/nimgame/player/HumanPlayer.h
Normal file
26
NimGame/game/nimgame/player/HumanPlayer.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// Created by JoachimWagner on 11.03.2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include "AbstractNimGamePlayer.h"
|
||||
|
||||
namespace atlas::game::nimgame::player {
|
||||
|
||||
class HumanPlayer: public AbstractNimGamePlayer{
|
||||
|
||||
public:
|
||||
explicit HumanPlayer(const std::string &name) : AbstractNimGamePlayer(name) {}
|
||||
|
||||
auto doTurn(const int &stones) const -> int override {
|
||||
|
||||
int turn;
|
||||
std::cout << "Es gibt " << stones << " Steine. Bitte nehmen Sie 1,2 oder 3!" << std::endl;
|
||||
std::cin >> turn;
|
||||
return turn;
|
||||
}
|
||||
};
|
||||
|
||||
} // atlas::game::nimgame::player
|
||||
33
NimGame/game/nimgame/player/OmaPlayer.h
Normal file
33
NimGame/game/nimgame/player/OmaPlayer.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// Created by JoachimWagner on 28.01.2025.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "time.h"
|
||||
#include <cstdlib>
|
||||
#include "AbstractNimGamePlayer.h"
|
||||
namespace atlas::game::nimgame::player {
|
||||
|
||||
class OmaPlayer: public AbstractNimGamePlayer{
|
||||
|
||||
public:
|
||||
explicit OmaPlayer(const std::string &name) : AbstractNimGamePlayer(name) {
|
||||
std::srand(time(nullptr));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[[nodiscard]]
|
||||
auto doTurn(const int &stones) const -> int override {
|
||||
const int result = std::rand() % 6;
|
||||
std::cout << "Oma nimmt " << result << " Steine." << std::endl;
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
} // game
|
||||
Loading…
Add table
Add a link
Reference in a new issue