Check-in [ab64875b14]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:changed databases for keeping track of buttons clicked
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:ab64875b1420a044f0a5c0cd820c87f80908175d
User & Date: hhammadu 2016-11-28 23:45:25
Context
2016-11-29
01:29
game.jl check-in: f1abf65d52 user: hhammadu tags: trunk
00:04
add move check-in: 43ad7c5a1d user: tien tags: trunk
2016-11-28
23:45
changed databases for keeping track of buttons clicked check-in: ab64875b14 user: hhammadu tags: trunk
23:06
initial empty check-in check-in: b3df9ce0bf user: hhammadu tags: trunk
Changes

Added databases.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
module databases
push!(LOAD_PATH,pwd())
using SQLite
export Create_Table
export updatePlayer
export updateMeta
export showData
export updateMoves
export updatePlayer
export Access_By_Position
export Access_By_Move_Number
export Length_Of_Tables
export Access_By_key
export InitializeScore
export getScore
export updateScore
export update_time
export get_time
export timed
export get_optval
export updategame
#Create Tables
########################################################################################################################################################################################

function Create_Table(db,name)
	SQLite.drop!(db, name; ifexists = true)
	if name == "meta"
		query="CREATE TABLE meta(key TEXT, value TEXT);"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	elseif name == "moves"
		query="CREATE TABLE moves(move_number INTEGER, move_type TEXT,sourcex INTEGER,sourcey INTEGER, targetx INTEGER, targety INTEGER, option TEXT, i_am_cheating INTEGER,targetx2 INTEGER,targety2 INTEGER);"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	elseif name == "Player"
		query="CREATE TABLE Player(player INTEGER,curr_x INTEGER, curr_y INTEGER, status INTEGER, promotion INTEGER, piece TEXT);"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	elseif name == "Score"
		query="CREATE TABLE Score(player INTEGER,score INTEGER);"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	elseif name == "game"
		query="CREATE TABLE game(option Text,value INTEGER);"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	end
end


########################################################################################################################################################################################





#Updating Tables
########################################################################################################################################################################################
function updategame(db,opt,val)
	stmt = SQLite.Stmt(db,"INSERT INTO game VALUES('$opt',$val);")
	SQLite.execute!(stmt)
end

function updatePlayer(db,player,curr_x, curr_y,status, promotion, piece)
	stmt=SQLite.Stmt(db,"INSERT INTO Player VALUES($player,$curr_x,$curr_y,$status,$promotion,'$piece');")
	SQLite.execute!(stmt)
end

function InitializeScore(db)
	stmt=SQLite.Stmt(db,"INSERT INTO Score VALUES(1,0);")
	SQLite.execute!(stmt)
	stmt2=SQLite.Stmt(db,"INSERT INTO Score VALUES(0,0);")
	SQLite.execute!(stmt2)
end

function updateScore(db,p1,p2)
	x=getScore(db)
	x1=x[1]+p1
	x2=x[2]+p2
	stmt=SQLite.Stmt(db,"UPDATE Score SET score = $x1 WHERE player = 1;")
	SQLite.execute!(stmt)
	stmt=SQLite.Stmt(db,"UPDATE Score SET score = $x2 WHERE player = 0;")
	SQLite.execute!(stmt)
end

function getScore(db)
	query = "SELECT score FROM Score;"
	x=SQLite.query(db,query)
	y1=get(x[1][1])
	y2=get(x[1][2])
	z=[y1,y2]
	return z
end

function timed(db)
	query="SELECT value FROM meta WHERE key = 'timed';"
	x=SQLite.query(db,query)
	y1=get(x[1][1])
	if y1 == "yes"
		return 1
	else 
		return 0
	end
end

function update_time(db,time,name)
	query = "SELECT value FROM meta WHERE key = '$name';"
	x = SQLite.query(db,query)
	y1=parse(get(x[1][1]))
	if name == "time_add"
		y1= y1 + time
	else
		y1 = y1 - time
	end
	stmt=SQLite.Stmt(db,"UPDATE meta SET value = '$y1' WHERE key = '$name';")
	SQLite.execute!(stmt)
	
end

function get_time(db,name)
	
	query = "SELECT value FROM meta WHERE key = '$name';"
	x = SQLite.query(db,query)
	y1=parse(get(x[1][1]))
	return y1
end

function get_optval(db,opt)
	query = "SELECT value FROM game WHERE option = '$opt';"
	x = SQLite.query(db,query)
	y = (get(x[1][1]))
	return y
end
function updateMeta(db,shogiType,cheating,timed,sente_time,gote_time)
	if shogiType == "S"
		query="INSERT INTO meta VALUES('type','standard');"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	elseif shogiType == "M"
		query="INSERT INTO meta VALUES('type','minishoghi');"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	else
		query="INSERT INTO meta VALUES('type','chushoghi');"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	end
    if cheating == "T"
		query="INSERT INTO meta VALUES('legality','cheating');"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	else
		query="INSERT INTO meta VALUES('legality','legal');"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	end
	if timed == "timed"
		query="INSERT INTO meta VALUES('timed','yes');"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	else
		query="INSERT INTO meta VALUES('timed','no');"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	end
    
	if timed == "timed"
		query="INSERT INTO meta VALUES('time_add','0');"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)

		query="INSERT INTO meta VALUES('sente_time','$sente_time');"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)

		query="INSERT INTO meta VALUES('gote_time','$gote_time');"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	end
	
	unixTime = time()
	query="INSERT INTO meta VALUES('seed','$unixTime');"
	stmt=SQLite.Stmt(db,query)
	SQLite.execute!(stmt)
end

# for values which you don't want to insert in database just type in 0 for that parameter.

function updateMoves(db,move_number, move_type ,sourcex, sourcey, targetx, targety, option, i_am_cheating, targetx2, targety2)

	if  sourcex==0 && sourcey==0 && targetx==0 && targety==0 && option==0 && i_am_cheating==0 && targetx2==0 && targety2==0
		query = "INSERT INTO moves (move_number,move_type) VALUES ($move_number,'$move_type');"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	elseif targetx2==0 && targety2==0 && option==0 && i_am_cheating==0 && sourcex!=0 && sourcey!=0 && targetx!=0 && targety!=0
		query = "INSERT INTO moves (move_number,move_type,sourcex,sourcey,targetx,targety) VALUES ($move_number,'$move_type',$sourcex,$sourcey,$targetx,$targety);"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	elseif targetx2==0 && targety2==0 && option==0 && i_am_cheating !=0 &&  sourcex!=0 && sourcey!=0 && targetx!=0 && targety!=0
		query = "INSERT INTO moves (move_number,move_type,sourcex,sourcey,targetx,targety,i_am_cheating) VALUES ($move_number,'$move_type',$sourcex,$sourcey,$targetx,$targety,$i_am_cheating);"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	elseif targetx2==0 && targety2==0 && i_am_cheating==0 && option!=0 && sourcex!=0 && sourcey!=0 && targetx!=0 && targety!=0
		query = "INSERT INTO moves (move_number,move_type,sourcex,sourcey,targetx,targety,option) VALUES ($move_number,'$move_type',$sourcex,$sourcey,$targetx,$targety,'$option');"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	elseif option==0 && i_am_cheating==0 && targetx2!=0 && targety2!=0  && sourcex!=0 && sourcey!=0 && targetx!=0 && targety!=0
		query = "INSERT INTO moves (move_number,move_type,sourcex,sourcey,targetx,targety,targetx2,targety2) VALUES ($move_number,'$move_type',$sourcex,$sourcey,$targetx,$targety,$targetx2,$targety2);"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	elseif option == 0 && targetx2!=0 && targety2!=0  && sourcex!=0 && sourcey!=0 && targetx!=0 && targety!=0 && i_am_cheating !=0
		query = "INSERT INTO moves (move_number,move_type,sourcex,sourcey,targetx,targety,i_am_cheating,targetx2,targety2) VALUES ($move_number,'$move_type',$sourcex,$sourcey,$targetx,$targety,$i_am_cheating,$targetx2,$targety2);"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	elseif i_am_cheating==0 && option != 0 && targetx2!=0 && targety2!=0  && sourcex!=0 && sourcey!=0 && targetx!=0 && targety!=0
	    query = "INSERT INTO moves (move_number,move_type,sourcex,sourcey,targetx,targety,option,targetx2,targety2) VALUES ($move_number,'$move_type',$sourcex,$sourcey,$targetx,$targety,'$option',$targetx2,$targety2);"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	else
		query = "INSERT INTO moves VALUES($move_number,'$move_type',$sourcex,$sourcey,$targetx,$targety,'$option',$i_am_cheating,$targetx2,$targety2);"
		stmt=SQLite.Stmt(db,query)
		SQLite.execute!(stmt)
	end

end


########################################################################################################################################################################################



#Querying Data
#########################################################################################################################################################################################

function showData(db,name)
	query="SELECT * FROM $name;"
	println(SQLite.query(db, query))
end

function Access_By_Move_Number(db,move_number)
	query = "SELECT * FROM moves WHERE move_number = $move_number;"
	x=SQLite.query(db,query)
	z=Extract_moves(x)
	return z
end

function Extract_moves(row)
	y1 = get(row[1][1])
	if isnull(row[2][1])
		y2 = "NULL"
	else
		y2 = get(row[2][1])
	end
	if isnull(row[3][1])
		y3 = "NULL"
	else
		y3 = get(row[3][1])
	end
	if isnull(row[4][1])
		y4 = "NULL"
	else
		y4 = get(row[4][1])
	end
	if isnull(row[5][1])
		y5 = "NULL"
	else
		y5 = get(row[5][1])
	end
	if isnull(row[6][1])
		y6 = "NULL"
	else
		y6 = get(row[6][1])
	end
	if isnull(row[7][1])
		y7 = "NULL"
	else
		y7 = get(row[7][1])
	end
	if isnull(row[8][1])
		y8 = "NULL"
	else
		y8 = get(row[8][1])
	end
	if isnull(row[9][1])
		y9 = "NULL"
	else
		y9 = get(row[9][1])
	end
	if isnull(row[10][1])
		y10 = "NULL"
	else
		y10 = get(row[10][1])
	end
	return [y1,y2,y3,y4,y5,y6,y7,y8,y9,y10]
end



function Access_By_Position(db,x,y,player)
	query = "SELECT * FROM Player WHERE curr_x = $x AND curr_y = $y AND player = $player;"
	x=SQLite.query(db,query)
	z=Extract_Position(x)
	return z
end

function Extract_Position(row)
	y1 = get(row[1][1])
  y2 = get(row[2][1])
  y3 = get(row[3][1])
  y4 = get(row[4][1])
  y5 = get(row[5][1])
  y6 = get(row[6][1])
  return [y1,y2,y3,y4,y5,y6]
end


function Access_By_key(db,key)
	query = "SELECT * FROM meta WHERE key = '$key';"
	x=SQLite.query(db,query)
	z=Extract_meta(x)
	return z
end

function Extract_meta(row)
	y1 = get(row[1][1])
	y2 = get(row[2][1])
  return [y1,y2]
end
########################################################################################################################################################################################



#Length_Of_Tables
##################################################################################################################################################################################

function Length_Of_Tables(db,table_name)
	query = "SELECT count(*) FROM $table_name;"
	x=SQLite.query(db,query)
	z=get(x[1][1])
	return z
end
###########################################################################################################################################################################################


end