-
Notifications
You must be signed in to change notification settings - Fork 1
/
move_user_resign.jl
31 lines (22 loc) · 1.04 KB
/
move_user_resign.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
#=move_user_resign.jl - the current user resigns, accepts 1 command line argument,<filename> => database
=#
module move_user_resign
using SQLite
function resign(database)
#database = ARGS[1] #/path/to/database/file {string}
db = SQLite.DB(database) #Opens the database gamefile
#= ---- Determines the move_number ---- =#
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
move_number = lastMoveID+1 #Current move number
#=-----UPDATE DATABASE W/MOVE-----=#
#Option will be dropped pieces abv
SQLite.query(db,"INSERT INTO moves (move_number, move_type)
VALUES ($(move_number),'resign');")
end
end