-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmove_cheat.jl
122 lines (83 loc) · 3.35 KB
/
move_cheat.jl
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#=move.jl - Updates the game file with a move, accepts 1 command line argument,<filename> => database
=#
include("square.jl")
include("dParse.jl")
module move_cheat
using ST
using dParse
using SQLite
#=----Parses the database and determines where pieces are on the board----=#
#= ---- Opens the Database for reading ---- =#
database = ARGS[1] #/path/to/database/file {string}
db = SQLite.DB(database) #Opens the database gamefile
#= ---- Determines whos turn it is (white or black) ---- =#
res = SQLite.query(db, """SELECT max("move_number") from moves;""") #Finds the last played move (maximum move_number)
lastMoveIDNullable = res[1,1] #SQL query with max move_number (POSSIBLY "NULL" if no moves have been made)
if (!isnull(lastMoveIDNullable)) #Checks that lastMoveID was not NULL
lastMoveID = get(res[1,1])#Parses the last move move_number as an Int
else #lastMoveID is NULL
lastMoveID = 0 #move_number "0" is unsused. This implies no moves have been made
end
#=---- Determines a move to make (AI integration below)----=#
move_number = lastMoveID+1 #The current move is move#: move_number
function isCheck()
if (even(move_number) == true)
team = "w"
else
team = "b"
#first finds the x y coordinates of king
for x in 1:9
for y in 1:9
if (k(board[x][y]) == true) #there's a king
if board[x][y].team == team
kingx = x
kingy = y
end
end
end
end
for x in 1:9
for y in 1:9
if (isEmpty(board[x][y]) == false)
unit = board[x][y].piece
team = board[x][y].team
if (moveValidate(unit, "move", team, x, y, kingx, kingy) == true)
return true #resign
end
end
end
end
return false
end
end
#=
#Todo: write AI: must define variables: move_type, sourcex, sourcey, targetx, targety, option, i_am_cheating
# get all of our pieces on board set numbers to them ####if piece is our piece its choosable
create array
# check every square if empty square dont add to list, if piece colour = opponent dont add, if ours add
if piece colour = our colour add to list
create temppiece
# choose random piece from list based on random number from list (rand mod listend)
find array length
do temppiece = rand % arraylength
# set temp piece to it
# use validate file to see what moves it can make, number them, put them in a list ####movevalidate
create another array, if piece -> target = movevalidate, add to list,
# make a move based on random number from list (rand mod listend)
makemove = rand % array2length
#random number part
#use random function mod max val it can be
=#
#=
if isCheck == true
SQLite.query(db,"INSERT INTO moves (move_number, move_type, sourcex, sourcey, targetx, targety, option, i_am_cheating)
VALUES ($(move_number),$(move_type),$sourcex, $sourcey,$targetx, $targety, $option, $(i_am_cheating));")
=#
# ---- Saves the determined move in the database ---- =#
SQLite.query(db,"INSERT INTO moves (move_number, move_type)
VALUES ($(move_number),'resign');")
#=
SQLite.query(db,"""INSERT INTO moves (move_number, move_type, sourcex, sourcey, targetx, targety, option, i_am_cheating)
VALUES ("$(move_number)","$(move_type)","$sourcex","$sourcey","$targetx","$targety", "$option", "$(i_am_cheating)")""";)
=#
end