forked from parismav87/src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhi.cpp
90 lines (65 loc) · 2.16 KB
/
hi.cpp
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
78
79
80
81
82
83
84
85
86
87
88
#include "lib_std_facilities.h"
#include <fstream>
#include "GameEngine.h"
#include "Bot.h"
int main()
{
GameEngine engine("C:\\Users\\itsupport\\eclipse-workspace\\hi\\src\\map10.txt", "C:\\Users\\itsupport\\eclipse-workspace\\hi\\src\\future10.txt"); //init game engine with map & future map.
Bot myBot; //init Bot
bool smart = false; //false = human, true = bot
while(engine.hasLegalMoves()){ //while the game isn't over
int x1, y1, x2, y2; //coordinates for next move. x1 y1 = tile 1 , x2 y2 = tile 2
int nextMoveInt;
int *nextMove = &nextMoveInt; // this is where the next move will be stored: [x1,y1,x2,y2]
if(smart){ //bot player
nextMove = myBot.getNextMove(engine.getMap(), nextMove); //get next move from bot.
//assign coordinates of next move
int tempx1 = nextMove[0];
int tempy1 = nextMove[1];
int tempx2 = nextMove[2];
int tempy2 = nextMove[3];
x1 = tempx1;
y1 = tempy1;
x2 = tempx2;
y2 = tempy2;
} else { //human player
//ask human for input
cout<<"Give the x-coordinate of the first tile"<<endl;
cin>>x1;
cout<<"Give the y-coordinate of the first tile"<<endl;
cin>>y1;
cout<<"Give the x-coordinate of the second tile"<<endl;
cin>>x2;
cout<<"Give the y-coordinate of the second tile"<<endl;
cin>>y2;
int tempx1 = x1;
int tempy1 = y1;
int tempx2 = x2;
int tempy2 = y2;
nextMove[0] = tempx1;
nextMove[1] = tempy1;
nextMove[2] = tempx2;
nextMove[3] = tempy2;
}
//check if the move is legal
if(engine.isLegalMove(x1, y1, x2, y2)){
int points=1; //first move always gets 1 point per tile
engine.makeMove(nextMove); //make the move
cout<<endl;
while(engine.needsUpdate()){ //while there is still tiles to break
engine.updateMap(points); //update the map
engine.restoreMap(); //copy map clone to original map
engine.printMap(); //print map on terminal
engine.printScore(); // print score on terminal
points+=1; //next cycle of tile breaking gets +1 point
}
}
else{ //move is invalid
cout<<"Invalid move, try again"<<endl;
}
}
//the end
cout<<"The game has ended"<<endl;
cout<<"Final Score: "<<engine.getScore()<<endl;
return 0;
}