Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added ConnectFour #19

Merged
merged 4 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
AccessModifierOffset: -1
AlignAfterOpenBracket: DontAlign
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AlwaysBreakBeforeMultilineStrings: false
BasedOnStyle: LLVM
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakStringLiterals: true
ColumnLimit: 120
Cpp11BracedListStyle: true
FixNamespaceComments: true
IncludeBlocks: Merge
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++17
UseCRLF: false
UseTab: false
23 changes: 22 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"files.associations": {
".nycrc": "json",
".env": "ini",
"*.ts.example": "typescript",
"*.lock": "yaml",
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
Expand Down Expand Up @@ -48,7 +52,24 @@
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp"
"typeinfo": "cpp",
"xstring": "cpp",
"compare": "cpp",
"concepts": "cpp",
"list": "cpp",
"xhash": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xtr1common": "cpp",
"xutility": "cpp",
"ios": "cpp",
"iostream": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocnum": "cpp",
"bitset": "cpp"
},
"C_Cpp.default.includePath": ["/usr/include/node", "${workspaceFolder}/include", "${workspaceFolder}/node_modules/node-addon-api"]
}
1 change: 1 addition & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"target_name": "skyra-ai",
"sources": [
"src/games/TicTacToe.cc",
"src/games/ConnectFour.cc",
"src/main.cc"
],
"include_dirs": [
Expand Down
21 changes: 21 additions & 0 deletions include/games/ConnectFour.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "utils/Players.hpp"
#include <array>
#include <cstdint>

namespace connect_four {
constexpr uint_fast8_t board_width = 7;
constexpr uint_fast8_t board_height = 6;
constexpr uint_fast8_t board_cells = board_width * board_height;

typedef std::array<Players, board_cells> ai_cells;
typedef std::array<uint_fast8_t, board_width> ai_remaining;

struct ai_board {
ai_cells cells;
ai_remaining remaining;
};

int_fast8_t position(ai_board& board, int_fast8_t remaining, int_fast8_t maximum_depth) noexcept;
} // namespace connect_four
17 changes: 10 additions & 7 deletions include/games/TicTacToe.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#pragma once

#include <cstdint>
#include <array>
#include "utils/Players.hpp"
#include <array>
#include <cstdint>

namespace tic_tac_toe {
constexpr uint_fast8_t board_width = 3;
constexpr uint_fast8_t board_height = 3;
constexpr uint_fast8_t board_cells = board_width * board_height;

namespace TicTacToe
{
typedef std::array<Players, 9> ai_board;
typedef std::array<Players, board_cells> ai_board;

int_fast8_t position(ai_board &board, int_fast8_t remaining) noexcept;
} // namespace TicTacToe
int_fast8_t position(ai_board& board, int_fast8_t remaining) noexcept;
} // namespace tic_tac_toe
62 changes: 0 additions & 62 deletions include/utils/Matrix2.hpp

This file was deleted.

7 changes: 1 addition & 6 deletions include/utils/Players.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@

#include <cstdint>

enum class Players : uint_fast8_t
{
Unset,
Player,
Machine
};
enum class Players : uint_fast8_t { Unset, Player, Machine };
6 changes: 4 additions & 2 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import bindings from 'bindings';

const addon = bindings('skyra-ai') as Addon;

export const ticTacToe = addon.TicTacToe;
export const ticTacToe = addon.ticTacToe;
export const connectFour = addon.connectFour;

export interface Addon {
TicTacToe(data: Uint8Array): number;
ticTacToe(data: Uint8Array): number;
connectFour(data: Uint8Array, maximumDepth?: number): number;
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
},
"keywords": [
"discord.js",
"klasa",
"bot",
"standalone"
],
Expand Down
Loading