Commit 7c6ea7ada0ac4d2a68f08ae1515b78e37c617ecd

Authored by Hakeem
1 parent d467b15e

orange monkey working, and stuff

guiapplication.cpp
... ... @@ -38,6 +38,9 @@ GuiApplication::GuiApplication(int& argc, char** argv)
38 38 connect(root_window, SIGNAL(initNewHumanGame()), this,
39 39 SLOT(initNewHumanGame()));
40 40  
  41 + connect(root_window, SIGNAL(initNewGameVsOrangeMonkeyAI()), this,
  42 + SLOT(initNewGameVsOrangeMonkeyAI()));
  43 +
41 44 connect(this, &GuiApplication::gameEnded, this,
42 45 &GuiApplication::endOfGameActions);
43 46  
... ... @@ -49,19 +52,33 @@ GuiApplication::GuiApplication(int& argc, char** argv)
49 52 }
50 53 }
51 54  
  55 +void GuiApplication::endOfTurn()
  56 +{
  57 + m_model.update();
  58 + if (m_game_engine.legalMovesCheck())
  59 +
  60 + emit enqueueNextTurn();
  61 +}
  62 +
52 63 void GuiApplication::startNextTurn()
53 64 {
54   - m_model.update();/*
55   - m_game_engine.switchCurrentPlayerId();*/
  65 + if (m_game_engine.currentPlayerType() == othello::PlayerType::AI){
  66 + m_game_engine.think(20s);
  67 + endOfTurn();
  68 + }
  69 +
56 70 }
57 71  
58 72 void GuiApplication::boardClicked(int pos)
59 73 {
  74 + if (m_game_engine.currentPlayerType() == othello::PlayerType::AI){
  75 + return;
  76 + }
60 77 auto success = m_game_engine.performMoveForCurrentHuman(othello::BitPos{pos});
61 78 if (!success)
62 79 return;
63 80  
64   - emit enqueueNextTurn();
  81 + endOfTurn();
65 82 }
66 83  
67 84 void GuiApplication::initNewHumanGame()
... ... @@ -69,18 +86,18 @@ void GuiApplication::initNewHumanGame()
69 86 m_game_engine.initPlayerType<othello::HumanPlayer, othello::PlayerId::One>();
70 87 m_game_engine.initPlayerType<othello::HumanPlayer, othello::PlayerId::Two>();
71 88 m_game_engine.initNewGame();
72   - //m_model.update();
  89 + m_model.update();
73 90 emit enqueueNextTurn();
74 91 }
75 92  
76   -/*void GuiApplication::initNewGameVsMonkeyAI()
  93 +void GuiApplication::initNewGameVsOrangeMonkeyAI()
77 94 {
78 95 m_game_engine.initPlayerType<othello::HumanPlayer, othello::PlayerId::One>();
79 96 m_game_engine.initPlayerType<othello::monkey_ais::OrangeMonkeyAI, othello::PlayerId::Two>();
80 97 m_game_engine.initNewGame();
81 98 m_model.update();
82 99 emit enqueueNextTurn();
83   -}*/
  100 +}
84 101  
85 102 void GuiApplication::endGameAndQuit() { QGuiApplication::quit(); }
86 103  
... ...
guiapplication.h
... ... @@ -27,10 +27,11 @@ private:
27 27 othello::OthelloGameEngine m_game_engine;
28 28 GameModel m_model;
29 29 QQmlApplicationEngine m_app;
  30 + void endOfTurn();
30 31  
31 32 private slots:
32 33 void initNewHumanGame();
33   -// void initNewGameVsMonkeyAI();
  34 + void initNewGameVsOrangeMonkeyAI();
34 35 void endGameAndQuit();
35 36 void endOfGameActions();
36 37 void startNextTurn();
... ...
resources/qml/gui.qml
... ... @@ -6,8 +6,8 @@ ApplicationWindow {
6 6 id: root
7 7  
8 8 signal initNewHumanGame()
9   - signal initNewGameVsMonkeyAI(string monkey_color)
10   - signal initNewMonkeyAIGame(string monkey_one_color, string monkey_two_color)
  9 + signal initNewGameVsOrangeMonkeyAI()
  10 + signal initNewMonkeyAIGame()
11 11 signal endGameAndQuit()
12 12 signal boardClicked(int board_pos)
13 13  
... ... @@ -24,7 +24,7 @@ ApplicationWindow {
24 24 visible: true
25 25  
26 26 width: 800
27   - height: 600
  27 + height: 800
28 28  
29 29 menuBar: MenuBar {
30 30 Menu {
... ... @@ -33,10 +33,10 @@ ApplicationWindow {
33 33 text: "New Game: Human Endeavour"
34 34 onTriggered: initNewHumanGame()
35 35 }
36   -/* MenuItem {
37   - text: "New Game: Human vs AI"
38   - onTriggered: initNewGameVsMonkeyAI()
39   - }*/
  36 + MenuItem {
  37 + text: "New Game: Human vs Orange Monkey"
  38 + onTriggered: initNewGameVsOrangeMonkeyAI()
  39 + }
40 40 MenuItem {
41 41 text: "Quit"
42 42 onTriggered: endGameAndQuit()
... ... @@ -62,6 +62,8 @@ ApplicationWindow {
62 62 property bool contains_mouse: false
63 63 property string player_one_color: "orange"
64 64 property string player_two_color: "blue"
  65 + property string player_one_hover_color: "yellow"
  66 + property string player_two_hover_color: "steelblue"
65 67  
66 68 Layout.fillHeight: true
67 69 Layout.fillWidth: true
... ... @@ -72,8 +74,8 @@ ApplicationWindow {
72 74 else return "black"
73 75 }
74 76 else if(contains_mouse) {
75   - if(gamemodel.currentPlayer === 0) return player_one_color
76   - else if(gamemodel.currentPlayer === 1) return player_two_color
  77 + if(gamemodel.currentPlayer === 0) return player_one_hover_color
  78 + else if(gamemodel.currentPlayer === 1) return player_two_hover_color
77 79 else return "black"
78 80 }
79 81 else return "white"
... ...