-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (61 loc) · 2.48 KB
/
Copy pathmain.cpp
File metadata and controls
77 lines (61 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "game.h"
#include <iostream>
#include <emscripten.h>
#include <emscripten/bind.h>
using namespace emscripten;
// This block exposes our C++ Game class to JavaScript
EMSCRIPTEN_BINDINGS(my_game_module) {
// First, teach Embind what a "pair of ints" is and how to build it
value_object<std::pair<int, int>>("IntPair")
.field("first", &std::pair<int, int>::first)
.field("second", &std::pair<int, int>::second);
class_<game>("Game")
.constructor<>() // This exposes the constructor (e.g., new Game())
.function("makeMove", &game::makeMove)
.function("checkWinner", &game::checkWinner)
.function("getBoardState", &game::getBoardState)
.function("reset", &game::reset)
.function("findBestMove", &game::findBestMove);
// We can't easily use printBoard, since it prints to the C++ console.
// Let's add a new function to get the board state instead!
};
// terminal game
// int main() {
// game ticTacToe;
// char currentPlayer = 'X';
// // A simple game loop that runs forever (for now)
// while (true) {
// ticTacToe.printBoard();
// // Ask currentPlayer for their move
// std::cout<<"Enter your move(1-9) player "<<currentPlayer<<" :";
// // Get input from std::cin
// int position;
// std::cin>>position;
// // Try to make the move using ticTacToe.makeMove()
// bool canMake = ticTacToe.makeMove(currentPlayer,position);
// // If the move was valid
// if(!canMake){
// std::cout << "Can not make this move for player " <<currentPlayer<<'\n';
// continue; // play again
// }
// // Check for a result
// char result = ticTacToe.checkWinner();
// // If the game is NOT ongoing, it's over!
// if (result != '_') {
// // Maybe print the final board one last time so they can see the win
// ticTacToe.printBoard();
// // Announce the winner or a draw based on 'result'
// if(result != 'D'){
// std::cout << "Congratulation!! You won! "<< currentPlayer << std::endl;
// }else
// {
// std::cout << "Game DRAW" << std::endl;
// }
// //The most important part: escape the loop!
// break;
// }
// // switch the player
// currentPlayer = (currentPlayer == 'X') ? 'O': 'X';
// }
// return 0;
// }