Commit 505e594e84ec207044414b2c838af9e7a1693a04

Authored by Hakeem
0 parents

h

.clang-format 0 → 100644
  1 +++ a/.clang-format
  1 +---
  2 +Language: Cpp
  3 +# BasedOnStyle: LLVM
  4 +AccessModifierOffset: -2
  5 +AlignAfterOpenBracket: Align
  6 +AlignConsecutiveAssignments: true
  7 +AlignConsecutiveDeclarations: true
  8 +AlignEscapedNewlinesLeft: false
  9 +AlignOperands: true
  10 +AlignTrailingComments: true
  11 +AllowAllParametersOfDeclarationOnNextLine: true
  12 +AllowShortBlocksOnASingleLine: false
  13 +AllowShortCaseLabelsOnASingleLine: false
  14 +AllowShortFunctionsOnASingleLine: All
  15 +AllowShortIfStatementsOnASingleLine: true
  16 +AllowShortLoopsOnASingleLine: true
  17 +AlwaysBreakAfterDefinitionReturnType: None
  18 +AlwaysBreakAfterReturnType: None
  19 +AlwaysBreakBeforeMultilineStrings: false
  20 +AlwaysBreakTemplateDeclarations: true
  21 +BinPackArguments: true
  22 +BinPackParameters: true
  23 +BraceWrapping:
  24 + AfterClass: false
  25 + AfterControlStatement: false
  26 + AfterEnum: false
  27 + AfterFunction: true
  28 + AfterNamespace: true
  29 + AfterObjCDeclaration: false
  30 + AfterStruct: false
  31 + AfterUnion: false
  32 + BeforeCatch: true
  33 + BeforeElse: true
  34 + IndentBraces: false
  35 +BreakBeforeBinaryOperators: All
  36 +BreakBeforeBraces: Custom
  37 +BreakBeforeTernaryOperators: true
  38 +BreakConstructorInitializersBeforeComma: false
  39 +ColumnLimit: 80
  40 +#CommentPragmas: '^ IWYU pragma:'
  41 +ConstructorInitializerAllOnOneLineOrOnePerLine: false
  42 +ConstructorInitializerIndentWidth: 2
  43 +ContinuationIndentWidth: 2
  44 +Cpp11BracedListStyle: true
  45 +DerivePointerAlignment: false
  46 +DisableFormat: false
  47 +ExperimentalAutoDetectBinPacking: false
  48 +FixNamespaceComments: true
  49 +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
  50 +#IncludeCategories:
  51 +# - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
  52 +# Priority: 2
  53 +# - Regex: '^(<|"(gtest|isl|json)/)'
  54 +# Priority: 3
  55 +# - Regex: '.*'
  56 +# Priority: 1
  57 +IndentCaseLabels: true
  58 +IndentWidth: 2
  59 +IndentWrappedFunctionNames: false
  60 +KeepEmptyLinesAtTheStartOfBlocks: true
  61 +MacroBlockBegin: ''
  62 +MacroBlockEnd: ''
  63 +MaxEmptyLinesToKeep: 10
  64 +NamespaceIndentation: All
  65 +ObjCBlockIndentWidth: 2
  66 +ObjCSpaceAfterProperty: false
  67 +ObjCSpaceBeforeProtocolList: true
  68 +PenaltyBreakBeforeFirstCallParameter: 19
  69 +PenaltyBreakComment: 300
  70 +PenaltyBreakFirstLessLess: 120
  71 +PenaltyBreakString: 1000
  72 +PenaltyExcessCharacter: 1000000
  73 +PenaltyReturnTypeOnItsOwnLine: 60
  74 +PointerAlignment: Left
  75 +ReflowComments: true
  76 +SortIncludes: false
  77 +SpaceAfterCStyleCast: false
  78 +SpaceBeforeAssignmentOperators: true
  79 +SpaceBeforeParens: ControlStatements
  80 +SpaceInEmptyParentheses: false
  81 +SpacesBeforeTrailingComments: 3
  82 +SpacesInAngles: false
  83 +SpacesInContainerLiterals: true
  84 +SpacesInCStyleCastParentheses: false
  85 +SpacesInParentheses: false
  86 +SpacesInSquareBrackets: false
  87 +Standard: Auto
  88 +TabWidth: 2
  89 +UseTab: Never
  90 +...
  91 +
... ...
CMakeLists.txt 0 → 100644
  1 +++ a/CMakeLists.txt
  1 +# Minimum CMake version required
  2 +cmake_minimum_required(VERSION 3.8)
  3 +
  4 +# Project
  5 +project(othello_qtclient VERSION 0.1 LANGUAGES CXX)
  6 +
  7 +
  8 +
  9 +
  10 +################################
  11 +# Find required Qt libraries
  12 +find_package(Qt5Core 5.11)
  13 +find_package(Qt5Quick 5.11)
  14 +find_package(Qt5Gui 5.11)
  15 +#find_package(Qt5Qml 5.11)
  16 +
  17 +
  18 +set( HDRS
  19 + gamemodel.h
  20 + guiapplication.h )
  21 +
  22 +set( SRCS
  23 + main.cpp
  24 + gamemodel.cpp
  25 + guiapplication.cpp )
  26 +
  27 +QT5_WRAP_CPP( HDRS_MOC
  28 + gamemodel.h
  29 + guiapplication.h )
  30 +
  31 +QT5_ADD_RESOURCES( RCCS_MOC
  32 + resources/qml.qrc )
  33 +
  34 +
  35 +add_executable( ${PROJECT_NAME}
  36 + ${SRCS} ${HDRS} ${HDRS_MOC} ${RCCS_MOC}
  37 + )
  38 +
  39 +# TURN ON C++17 FEATURES
  40 +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17 )
  41 +
  42 +# Compiler spesific options
  43 +target_compile_options(${PROJECT_NAME}
  44 + PUBLIC $<$<CXX_COMPILER_ID:Clang>:
  45 + # Mandatory compiler flags
  46 + -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic
  47 + -pedantic -Werror
  48 +
  49 + # Disable clangs overtidyness for documentation
  50 + -Wno-documentation
  51 +
  52 + # Deal with Qt - which is not 100% clangified ><
  53 + -Wno-padded
  54 + -Wno-redundant-parens
  55 +
  56 + # Stuff we want to deal with later
  57 + -Wno-weak-vtables
  58 + >
  59 + PUBLIC $<$<CXX_COMPILER_ID:GNU>:
  60 + # Mandatory compiler flags
  61 + -pedantic -Wall -Werror
  62 + >
  63 + )
  64 +
  65 +
  66 +
  67 +##############################
  68 +# Configure othello interfaces
  69 +find_package(othello_interfaces REQUIRED CONFIG NO_DEFAULT_PATH)
  70 +
  71 +###############################
  72 +# Configure othello game engine
  73 +find_package(othello_game_engine REQUIRED CONFIG NO_DEFAULT_PATH)
  74 +
  75 +
  76 +#####################################
  77 +# Setup/configure target dependencies
  78 +target_link_libraries( ${PROJECT_NAME}
  79 + Qt5::Core
  80 + Qt5::Quick
  81 + Qt5::Gui
  82 +# Qt5::3DQuick
  83 +# Qt5::3DExtras
  84 + othello::othello_interfaces
  85 + othello::othello_game_engine
  86 + )
... ...
CMakeLists.txt.user 0 → 100644
  1 +++ a/CMakeLists.txt.user
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE QtCreatorProject>
  3 +<!-- Written by QtCreator 4.7.0, 2018-09-19T08:36:15. -->
  4 +<qtcreator>
  5 + <data>
  6 + <variable>EnvironmentId</variable>
  7 + <value type="QByteArray">{bb76aeff-9571-4144-9f49-011ee88054ea}</value>
  8 + </data>
  9 + <data>
  10 + <variable>ProjectExplorer.Project.ActiveTarget</variable>
  11 + <value type="int">0</value>
  12 + </data>
  13 + <data>
  14 + <variable>ProjectExplorer.Project.EditorSettings</variable>
  15 + <valuemap type="QVariantMap">
  16 + <value type="bool" key="EditorConfiguration.AutoIndent">true</value>
  17 + <value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
  18 + <value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
  19 + <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
  20 + <value type="QString" key="language">Cpp</value>
  21 + <valuemap type="QVariantMap" key="value">
  22 + <value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
  23 + </valuemap>
  24 + </valuemap>
  25 + <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
  26 + <value type="QString" key="language">QmlJS</value>
  27 + <valuemap type="QVariantMap" key="value">
  28 + <value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
  29 + </valuemap>
  30 + </valuemap>
  31 + <value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
  32 + <value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
  33 + <value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
  34 + <value type="int" key="EditorConfiguration.IndentSize">4</value>
  35 + <value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
  36 + <value type="int" key="EditorConfiguration.MarginColumn">80</value>
  37 + <value type="bool" key="EditorConfiguration.MouseHiding">true</value>
  38 + <value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
  39 + <value type="int" key="EditorConfiguration.PaddingMode">1</value>
  40 + <value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
  41 + <value type="bool" key="EditorConfiguration.ShowMargin">false</value>
  42 + <value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
  43 + <value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
  44 + <value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
  45 + <value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
  46 + <value type="int" key="EditorConfiguration.TabSize">8</value>
  47 + <value type="bool" key="EditorConfiguration.UseGlobal">true</value>
  48 + <value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
  49 + <value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
  50 + <value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
  51 + <value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
  52 + <value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
  53 + </valuemap>
  54 + </data>
  55 + <data>
  56 + <variable>ProjectExplorer.Project.PluginSettings</variable>
  57 + <valuemap type="QVariantMap">
  58 + <valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey">
  59 + <value type="QString">-fno-delayed-template-parsing</value>
  60 + </valuelist>
  61 + <value type="bool" key="ClangCodeModel.UseGlobalConfig">true</value>
  62 + </valuemap>
  63 + </data>
  64 + <data>
  65 + <variable>ProjectExplorer.Project.Target.0</variable>
  66 + <valuemap type="QVariantMap">
  67 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.11.2 MSVC2017 64bit</value>
  68 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.11.2 MSVC2017 64bit</value>
  69 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5112.win64_msvc2017_64_kit</value>
  70 + <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
  71 + <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
  72 + <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
  73 + <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
  74 + <valuelist type="QVariantList" key="CMake.Configuration">
  75 + <value type="QString">CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}</value>
  76 + <value type="QString">CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}</value>
  77 + <value type="QString">CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}</value>
  78 + <value type="QString">QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}</value>
  79 + <value type="QString">othello_game_engine_DIR:PATH=D:/slimk/Documents/STE6274_2018/BUILDENGINE/cmake</value>
  80 + <value type="QString">othello_interfaces_DIR:PATH=D:/slimk/Documents/STE6274_2018/BUILDINTERFACE/cmake</value>
  81 + </valuelist>
  82 + <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:/slimk/Documents/STE6274_2018/BUILDCLIENT</value>
  83 + <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
  84 + <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
  85 + <value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
  86 + <valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
  87 + <value type="QString">all</value>
  88 + </valuelist>
  89 + <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
  90 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">CMake Build</value>
  91 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
  92 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
  93 + </valuemap>
  94 + <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
  95 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
  96 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
  97 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
  98 + </valuemap>
  99 + <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
  100 + <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
  101 + <value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
  102 + <valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
  103 + <value type="QString">all</value>
  104 + </valuelist>
  105 + <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
  106 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">CMake Build</value>
  107 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
  108 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
  109 + </valuemap>
  110 + <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
  111 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
  112 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
  113 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
  114 + </valuemap>
  115 + <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
  116 + <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
  117 + <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
  118 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Default</value>
  119 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value>
  120 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
  121 + </valuemap>
  122 + <value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
  123 + <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
  124 + <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
  125 + <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
  126 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
  127 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
  128 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
  129 + </valuemap>
  130 + <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
  131 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy Configuration</value>
  132 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
  133 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
  134 + </valuemap>
  135 + <value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
  136 + <valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
  137 + <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
  138 + <value type="bool" key="Analyzer.QmlProfiler.AggregateTraces">false</value>
  139 + <value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
  140 + <value type="uint" key="Analyzer.QmlProfiler.FlushInterval">1000</value>
  141 + <value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
  142 + <value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
  143 + <valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
  144 + <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
  145 + <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
  146 + <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
  147 + <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
  148 + <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
  149 + <value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
  150 + <value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
  151 + <value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
  152 + <value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
  153 + <value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
  154 + <valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
  155 + <value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
  156 + <value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
  157 + <value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
  158 + <value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
  159 + <value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
  160 + <valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
  161 + <value type="int">0</value>
  162 + <value type="int">1</value>
  163 + <value type="int">2</value>
  164 + <value type="int">3</value>
  165 + <value type="int">4</value>
  166 + <value type="int">5</value>
  167 + <value type="int">6</value>
  168 + <value type="int">7</value>
  169 + <value type="int">8</value>
  170 + <value type="int">9</value>
  171 + <value type="int">10</value>
  172 + <value type="int">11</value>
  173 + <value type="int">12</value>
  174 + <value type="int">13</value>
  175 + <value type="int">14</value>
  176 + </valuelist>
  177 + <value type="QString" key="CMakeProjectManager.CMakeRunConfiguration.Arguments"></value>
  178 + <value type="QString" key="CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory"></value>
  179 + <value type="QString" key="CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory.default">D:/slimk/Documents/STE6274_2018/BUILDCLIENT</value>
  180 + <value type="int" key="PE.EnvironmentAspect.Base">2</value>
  181 + <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
  182 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">othello_qtclient</value>
  183 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
  184 + <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeRunConfiguration.othello_qtclient
  185 +D:/slimk/Documents/STE6274_2018/othello_qtclient/</value>
  186 + <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
  187 + <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
  188 + <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
  189 + <value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
  190 + <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
  191 + <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
  192 + </valuemap>
  193 + <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
  194 + </valuemap>
  195 + </data>
  196 + <data>
  197 + <variable>ProjectExplorer.Project.TargetCount</variable>
  198 + <value type="int">1</value>
  199 + </data>
  200 + <data>
  201 + <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
  202 + <value type="int">18</value>
  203 + </data>
  204 + <data>
  205 + <variable>Version</variable>
  206 + <value type="int">18</value>
  207 + </data>
  208 +</qtcreator>
... ...
cmake/othello_qtclient-config.cmake.in 0 → 100644
  1 +++ a/cmake/othello_qtclient-config.cmake.in
  1 +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
  2 +message(STATUS "Found @PROJECT_NAME@")
... ...
gamemodel.cpp 0 → 100644
  1 +++ a/gamemodel.cpp
  1 +#include "gamemodel.h"
  2 +
  3 +GameModel::GameModel(const othello::OthelloGameEngine& game_engine,
  4 + QObject* parent)
  5 + : QAbstractListModel(parent), m_game_engine{game_engine}
  6 +{
  7 +}
  8 +
  9 +int GameModel::rowCount(const QModelIndex& parent) const
  10 +{
  11 + if (parent.isValid()) return 0;
  12 + return int(boardSize());
  13 +}
  14 +
  15 +QVariant GameModel::data(const QModelIndex& index, int role) const
  16 +{
  17 + if (!index.isValid()) return QVariant();
  18 +
  19 + const size_t st_row = size_t(boardSize() - index.row() - 1);
  20 + const auto piece_id = othello::BitPos(st_row);
  21 +
  22 + const auto occupied = othello::utility::occupied(m_game_engine.board(), piece_id);
  23 +
  24 +
  25 + if (role == OccupiedRole)
  26 + return occupied;
  27 + else if (role == PlayerNrRole) {
  28 +
  29 + if (!occupied) {
  30 +
  31 + return QVariant(-1);
  32 + }
  33 +
  34 + if (othello::utility::occupied(m_game_engine.pieces(othello::PlayerId::One),
  35 + piece_id)) {
  36 + return QVariant(uint(othello::PlayerId::One));
  37 + }
  38 + else if (othello::utility::occupied(
  39 + m_game_engine.pieces(othello::PlayerId::Two), piece_id)) {
  40 + return QVariant(uint(othello::PlayerId::Two));
  41 + }
  42 + }
  43 + else if (role == PieceNrRole) {
  44 +
  45 + return QVariant(int(piece_id.value()));
  46 + }
  47 +
  48 +
  49 + return QVariant();
  50 +}
  51 +
  52 +int GameModel::boardSize() const { return int(othello::detail::computeBoardSize()); }
  53 +
  54 +uint GameModel::currentPlayer() const {
  55 +
  56 + return uint(m_game_engine.currentPlayerId());
  57 +}
  58 +
  59 +QHash<int, QByteArray> GameModel::roleNames() const
  60 +{
  61 + QHash<int, QByteArray> role_names;
  62 + role_names[OccupiedRole] = "occupied";
  63 + role_names[PlayerNrRole] = "playernr";
  64 + role_names[PieceNrRole] = "piecenr";
  65 +
  66 + return role_names;
  67 +}
  68 +
  69 +void GameModel::update()
  70 +{
  71 + beginResetModel();
  72 + endResetModel();
  73 + emit boardSizeChanged(othello::detail::computeBoardSize());
  74 + emit currentPlayerChanged(size_t(m_game_engine.currentPlayerId()));
  75 +}
... ...
gamemodel.h 0 → 100644
  1 +++ a/gamemodel.h
  1 +#ifndef GAMEMODEL_H
  2 +#define GAMEMODEL_H
  3 +
  4 +
  5 +// cclibrary
  6 +#include <engine.h>
  7 +
  8 +// qt
  9 +#include <QAbstractListModel>
  10 +#include <QPoint>
  11 +
  12 +
  13 +// stl
  14 +#include <memory>
  15 +
  16 +
  17 +
  18 +class GameModel : public QAbstractListModel {
  19 + Q_OBJECT
  20 +public:
  21 + Q_PROPERTY(int boardSize READ boardSize NOTIFY boardSizeChanged)
  22 + Q_PROPERTY(uint currentPlayer READ currentPlayer NOTIFY currentPlayerChanged)
  23 +
  24 + enum ModelRoles { OccupiedRole = Qt::UserRole + 1, PlayerNrRole, PieceNrRole };
  25 +
  26 + GameModel(const othello::OthelloGameEngine& game_engine,
  27 + QObject* parent = nullptr);
  28 + ~GameModel() override = default;
  29 +
  30 + int rowCount(const QModelIndex& parent = QModelIndex()) const override;
  31 + QVariant data(const QModelIndex& index, int role) const override;
  32 + QHash<int, QByteArray> roleNames() const override;
  33 +
  34 +
  35 +public slots:
  36 + void update();
  37 +
  38 +private:
  39 + const othello::OthelloGameEngine& m_game_engine;
  40 +
  41 + int boardSize() const;
  42 + uint currentPlayer() const;
  43 +
  44 +signals:
  45 + void boardSizeChanged(size_t);
  46 + void currentPlayerChanged(size_t);
  47 +};
  48 +
  49 +
  50 +
  51 +
  52 +
  53 +#endif // GAMEMODEL_H
... ...
guiapplication.cpp 0 → 100644
  1 +++ a/guiapplication.cpp
  1 +#include "guiapplication.h"
  2 +
  3 +// othello game library
  4 +#include <orangemonkey_ai.h>
  5 +
  6 +
  7 +// qt
  8 +#include <QQmlContext>
  9 +#include <QQuickItem>
  10 +#include <QQuickWindow>
  11 +#include <QTimer>
  12 +#include <QDebug>
  13 +#include <QThread>
  14 +
  15 +// stl
  16 +#include <chrono>
  17 +using namespace std::chrono_literals;
  18 +
  19 +
  20 +GuiApplication::GuiApplication(int& argc, char** argv)
  21 + : QGuiApplication(argc, argv),
  22 + m_game_engine{}, m_model{m_game_engine}, m_app{}
  23 +{
  24 +
  25 + m_app.rootContext()->setContextProperty("gamemodel", &m_model);
  26 +
  27 + m_app.load(QUrl("qrc:/qml/gui.qml"));
  28 +
  29 + auto* root_window = qobject_cast<QQuickWindow*>(m_app.rootObjects().first());
  30 + if (root_window) {
  31 +
  32 + connect(root_window, SIGNAL(endGameAndQuit()), this,
  33 + SLOT(endGameAndQuit()));
  34 +
  35 + connect(root_window, SIGNAL(boardClicked(int)), this,
  36 + SLOT(boardClicked(int)));
  37 +
  38 + connect(root_window, SIGNAL(initNewHumanGame()), this,
  39 + SLOT(initNewHumanGame()));
  40 +
  41 + connect(this, &GuiApplication::gameEnded, this,
  42 + &GuiApplication::endOfGameActions);
  43 +
  44 + connect(this, &GuiApplication::enqueueNextTurn, this,
  45 + &GuiApplication::startNextTurn);
  46 +
  47 + connect(this, SIGNAL(displayFinalScores(int,int)),
  48 + root_window, SIGNAL(displayFinalScores(int,int)));
  49 + }
  50 +}
  51 +
  52 +void GuiApplication::startNextTurn()
  53 +{
  54 +
  55 +}
  56 +
  57 +void GuiApplication::initNewHumanGame()
  58 +{
  59 + m_game_engine.initPlayerType<othello::HumanPlayer, othello::PlayerId::One>();
  60 + m_game_engine.initPlayerType<othello::HumanPlayer, othello::PlayerId::Two>();
  61 + m_game_engine.initNewGame();
  62 + m_model.update();
  63 + emit enqueueNextTurn();
  64 +}
  65 +
  66 +/*void GuiApplication::initNewGameVsMonkeyAI()
  67 +{
  68 + m_game_engine.initPlayerType<othello::HumanPlayer, othello::PlayerId::One>();
  69 + m_game_engine.initPlayerType<othello::monkey_ais::OrangeMonkeyAI, othello::PlayerId::Two>();
  70 + m_game_engine.initNewGame();
  71 + m_model.update();
  72 + emit enqueueNextTurn();
  73 +}*/
  74 +
  75 +void GuiApplication::endGameAndQuit() { QGuiApplication::quit(); }
  76 +
  77 +
  78 +void GuiApplication::endOfGameActions()
  79 +{
  80 +}
... ...
guiapplication.h 0 → 100644
  1 +++ a/guiapplication.h
  1 +#ifndef GUIAPPLICATION_H
  2 +#define GUIAPPLICATION_H
  3 +
  4 +
  5 +// local
  6 +#include "gamemodel.h"
  7 +
  8 +// othello library
  9 +#include <engine.h>
  10 +
  11 +// qt
  12 +#include <QGuiApplication>
  13 +#include <QQmlApplicationEngine>
  14 +#include <QSizeF>
  15 +
  16 +// stl
  17 +#include <memory>
  18 +
  19 +
  20 +class GuiApplication : public QGuiApplication {
  21 + Q_OBJECT
  22 +public:
  23 + GuiApplication(int& argc, char** argv);
  24 + ~GuiApplication() override = default;
  25 +
  26 +private:
  27 + othello::OthelloGameEngine m_game_engine;
  28 + GameModel m_model;
  29 + QQmlApplicationEngine m_app;
  30 +
  31 +private slots:
  32 + void initNewHumanGame();
  33 +// void initNewGameVsMonkeyAI();
  34 + void endGameAndQuit();
  35 + void endOfGameActions();
  36 + void startNextTurn();
  37 + void boardClicked(int);
  38 +
  39 +signals:
  40 + void enqueueNextTurn();
  41 + void gameEnded();
  42 + void displayFinalScores(int player_one_score, int player_two_score);
  43 +
  44 +}; // END class GuiApplication
  45 +
  46 +#endif // GUIAPPLICATION_H
... ...
main.cpp 0 → 100644
  1 +++ a/main.cpp
  1 +
  2 +#include "guiapplication.h"
  3 +
  4 +// engine
  5 +#include <engine.h>
  6 +#include <orangemonkey_ai.h>
  7 +
  8 +// stl
  9 +#include <exception>
  10 +#include <string>
  11 +#include <iostream>
  12 +
  13 +int main(int argc, char** argv) try {
  14 +
  15 + // Start application
  16 + GuiApplication app(argc, argv);
  17 +
  18 + return app.exec();
  19 +}
  20 +catch (std::string exception) {
  21 + std::cout << "Runtime exception: " << exception << std::endl;
  22 +}
  23 +catch (std::runtime_error exception) {
  24 + std::cout << "Runtime exception: " << exception.what() << std::endl;
  25 +}
... ...
resources/qml.qrc 0 → 100644
  1 +++ a/resources/qml.qrc
  1 +<RCC>
  2 + <qresource prefix="/">
  3 + <file>qml/gui.qml</file>
  4 + </qresource>
  5 +</RCC>
... ...
resources/qml/gui.qml 0 → 100644
  1 +++ a/resources/qml/gui.qml
  1 +import QtQuick 2.0
  2 +import QtQuick.Layouts 1.0
  3 +import QtQuick.Controls 1.4
  4 +
  5 +ApplicationWindow {
  6 + id: root
  7 +
  8 + signal initNewHumanGame()
  9 + signal initNewGameVsMonkeyAI(string monkey_color)
  10 + signal initNewMonkeyAIGame(string monkey_one_color, string monkey_two_color)
  11 + signal endGameAndQuit()
  12 + signal boardClicked(int board_pos)
  13 +
  14 + signal displayFinalScores(int player_one_score, int player_two_score)
  15 +
  16 + onDisplayFinalScores: {
  17 + final_score_window.player_one_final_score = player_one_score
  18 + final_score_window.player_two_final_score = player_two_score
  19 + final_score_window.visible = true
  20 +
  21 + console.debug("Player scores: " + player_one_score + " vs. " + player_two_scores)
  22 + }
  23 +
  24 + visible: true
  25 +
  26 + width: 800
  27 + height: 600
  28 +
  29 + menuBar: MenuBar {
  30 + Menu {
  31 + title: "Game"
  32 + MenuItem {
  33 + text: "New Game: Human Endeavour"
  34 + onTriggered: initNewHumanGame()
  35 + }
  36 +/* MenuItem {
  37 + text: "New Game: Human vs AI"
  38 + onTriggered: initNewGameVsMonkeyAI()
  39 + }*/
  40 + MenuItem {
  41 + text: "Quit"
  42 + onTriggered: endGameAndQuit()
  43 + }
  44 + }
  45 + }
  46 +
  47 +
  48 + GridLayout {
  49 + anchors.fill: parent
  50 + columns: 8
  51 + rows: 8
  52 + columnSpacing: 0.2
  53 + rowSpacing: 0.2
  54 +
  55 +
  56 + Repeater {
  57 + model: VisualDataModel {
  58 + model: gamemodel
  59 + delegate: Rectangle {
  60 +
  61 + id: piece_rec
  62 + property bool contains_mouse: false
  63 + property string player_one_color: "orange"
  64 + property string player_two_color: "blue"
  65 +
  66 + Layout.fillHeight: true
  67 + Layout.fillWidth: true
  68 + color: {
  69 + if (occupied) {
  70 + if(playernr == 0) return player_one_color
  71 + else if(playernr == 1) return player_two_color
  72 + else return "black"
  73 + }
  74 + else if(contains_mouse) {
  75 + if(gamemodel.currentPlayer === 0) return player_one_color
  76 + else if(gamemodel.currentPlayer === 1) return player_two_color
  77 + else return "black"
  78 + }
  79 + else return "white"
  80 + }
  81 +
  82 + border.color: "black"
  83 + border.width: 1
  84 + MouseArea {
  85 + anchors.fill: parent
  86 + onClicked: {
  87 + console.debug("Piece nr: " + piecenr)
  88 + boardClicked(piecenr)
  89 + }
  90 +
  91 + hoverEnabled: true
  92 + onContainsMouseChanged: piece_rec.contains_mouse = containsMouse
  93 +
  94 + }
  95 + }
  96 + }
  97 + }
  98 + }
  99 +
  100 + Rectangle {
  101 + id: final_score_window
  102 + visible: false
  103 +
  104 + property int player_one_final_score: 0
  105 + property int player_two_final_score: 0
  106 +
  107 + anchors.fill: parent
  108 + anchors.margins: 50
  109 +
  110 + color: "red"
  111 + opacity: 0.8
  112 +
  113 + ColumnLayout {
  114 + anchors.fill: parent
  115 + anchors.margins: 20
  116 +
  117 + Text{ Layout.preferredWidth: parent.width; height: 20;
  118 + text: "Game Over!" }
  119 + Item{ height: 20}
  120 + Text{ Layout.preferredWidth: parent.width; height: 20;
  121 + text: "Player one: " + final_score_window.player_one_final_score}
  122 + Text{ Layout.preferredWidth: parent.width; height: 20;
  123 + text: "Player two: " + final_score_window.player_two_final_score}
  124 + Item{ Layout.fillHeight: true}
  125 + Button{ text: "Ok"; onClicked: final_score_window.visible = false }
  126 + }
  127 +
  128 + }
  129 +}
... ...