Diff

Differences From Artifact [1a09bf2e0b]:

To Artifact [d5c2744ab0]:


1
2
3

4
5
6
7

8
9
10
11
12
13
14
1
2

3
4
5
6

7
8
9
10
11
12
13
14


-
+



-
+







# limited move options

global pieceValTenjiku = Dict{String, Int64}("_" => 0, "bishop" => 10, "bishop general" => 21, "blind tiger" => 3, "copper general" => 2, "chariot soldier" => 18, "dog" => 1, "drunk elephant" => 3, "dragon horse" => 12, "dragon king" => 14, "ferocious leopard" => 3, "flying ox" => 16, "flying stag" => 9, "fire demon" => 83, "free boar" => 16, "free eagle" => 22, "gold general" => 3, "great general" => 45, "heavenly tetrarch" => 12, "horned falcon" => 19, "iron general" => 2, "king" => 500, "kirin" => 3, "lance" => 6, "lion hawk" => 25, "lion" => 18, "multi general" => 6, "knight" => 1, "pawn" => 1, "phoenix" => 3, "queen" => 22, "rook" => 12, "reverse chariot" => 6, "rook general" => 23, "silver general" => 2, "soaring eagle" => 18, "side mover" => 7, "side soldier" => 7, "vice general" => 39, "vertical mover" => 7, "vertical soldier" => 8, "water buffalo" => 17, "whale" => 10, "white horse" => 14)
global pieceValTenjiku = Dict{String, Int64}("bishop" => 10, "bishop general" => 21, "blind tiger" => 3, "copper general" => 2, "chariot soldier" => 18, "dog" => 1, "drunk elephant" => 3, "dragon horse" => 12, "dragon king" => 14, "ferocious leopard" => 3, "flying ox" => 16, "flying stag" => 9, "fire demon" => 83, "free boar" => 16, "free eagle" => 22, "gold general" => 3, "great general" => 45, "heavenly tetrarch" => 12, "horned falcon" => 19, "iron general" => 2, "king" => 500, "kirin" => 3, "lance" => 6, "lion hawk" => 25, "lion" => 18, "multi general" => 6, "knight" => 1, "pawn" => 1, "phoenix" => 3, "queen" => 22, "rook" => 12, "reverse chariot" => 6, "rook general" => 23, "silver general" => 2, "soaring eagle" => 18, "side mover" => 7, "side soldier" => 7, "vice general" => 39, "vertical mover" => 7, "vertical soldier" => 8, "water buffalo" => 17, "whale" => 10, "white horse" => 14)

global rangeJumpPriority = Dict{String, Int64}("_" => 0, "bishop" => 0, "bishop general" => 1, "blind tiger" => 0, "copper general" => 0, "chariot soldier" => 0, "dog" => 0, "drunk elephant" => 0, "dragon horse" => 0, "dragon king" => 0, "ferocious leopard" => 0, "flying ox" => 0, "flying stag" => 0, "fire demon" => 0, "free boar" => 0, "free eagle" => 0, "gold general" => 0, "great general" => 3, "heavenly tetrarch" => 0, "horned falcon" => 0, "iron general" => 0, "king" => 4, "kirin" => 0, "lance" => 0, "lion hawk" => 0, "lion" => 0, "multi general" => 0, "knight" => 0, "pawn" => 0, "phoenix" => 0, "queen" => 0, "rook" => 0, "reverse chariot" => 0, "rook general" => 1, "silver general" => 0, "soaring eagle" => 0, "side mover" => 0, "side soldier" => 0, "vice general" => 2, "vertical mover" => 0, "vertical soldier" => 0, "water buffalo" => 0, "whale" => 0, "white horse" => 0)

global pieceValChu = Dict{String, Int64}("_" => 0, "lion" => 20, "queen" => 12, "dragon king" => 8, "soaring eagle" => 11, "dragon horse" => 7, "horned falcon" => 10, "rook" => 6, "bishop" => 5, "vertical mover" => 4, "flying ox" => 8, "side mover" => 4, "free boar" => 8, "king" => 50, "phoenix" => 3, "kirin" => 3, "reverse chariot" => 3, "whale" => 5 , "lance" => 3, "white horse" => 7, "drunk elephant" => 3, "gold general" => 3, "ferocious leopard" => 3, "blind tiger" => 3, "flying stag" => 6, "silver general" => 2, "copper general" => 2, "go between" => 1, "pawn" => 1)
global pieceValChu = Dict{String, Int64}("lion" => 20, "queen" => 12, "dragon king" => 8, "soaring eagle" => 11, "dragon horse" => 7, "horned falcon" => 10, "rook" => 6, "bishop" => 5, "vertical mover" => 4, "flying ox" => 8, "side mover" => 4, "free boar" => 8, "king" => 50, "phoenix" => 3, "kirin" => 3, "reverse chariot" => 3, "whale" => 5 , "lance" => 3, "white horse" => 7, "drunk elephant" => 3, "gold general" => 3, "ferocious leopard" => 3, "blind tiger" => 3, "flying stag" => 6, "silver general" => 2, "copper general" => 2, "go between" => 1, "pawn" => 1)

global pieceVal = Dict{String,Int64}("pawn"=>1, "pawn promoted" =>2, "lance" =>4, "lance promomted" =>5, "knight" =>6,
"knight promoted" =>7, "silver general" =>7,"silver general promoted" =>8, "gold general" =>8, "bishop" =>11, "rook" =>13, "bishop promoted" =>15, "rook promoted" =>17, "king"=>50)

global prStandard = Dict{String, String}("rook promoted" => "dragon king","bishop promoted" => "dragon horse","silver general promoted" => "gold general",
 	"knight promoted" => "gold general", "lance promoted" => "gold general", "pawn promoted" => "gold general")
global prTenjiku = Dict{String,String}("bishop promoted" => "dragon horse", "bishop general promoted" => "vice general",
82
83
84
85
86
87
88


89
90
91
92
93
94
95
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97







+
+







#global tempMoveChoice2 = Array{Int64}(8) # Only used for double captures
global strength = -1
global whitePrison = []
global blackPrison = []
global chessboard
global tempChessboard

global currTurn

type moveOffset
	row::Int64
	col::Int64
end

type piece
	display::String
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
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







+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







				chessboard[i, j].WAttack = 0
				chessboard[i, j].BAttack = 0
			end
		end
	end
	for i in 1:dim
		for j in 1:dim
			if chessboard[i, j].side == currTurn
			if chessboard[i, j].name == defBishop
				defBishopMove(i, j, option)
			elseif chessboard[i, j].name == defBishopGeneral
				defBishopGeneralMove(i, j, option)
			elseif chessboard[i, j].name == defBlindTiger
				defBlindTigerMove(i, j, option)
			elseif chessboard[i, j].name == defCopperGeneral
				defCopperGeneralMove(i, j, option)
			elseif chessboard[i, j].name == defChariotSoldier
				defChariotSoldierMove(i, j, option)
			elseif chessboard[i, j].name == defDog
				defDogMove(i, j, option)
			elseif chessboard[i, j].name == defDrunkElephant
				defDrunkElephantrMove(i, j, option)
			elseif chessboard[i, j].name == defDragonHorse
				defDragonHorseMove(i, j, option)
			elseif chessboard[i, j].name == defDragonKing
				defDragonKingMove(i, j, option)
			elseif chessboard[i, j].name == defFerociousLeopard
				defFerociousLeopardMove(i, j, option)
			elseif chessboard[i, j].name == defFireDemon
				defFireDemonMove(i, j, option)
			elseif chessboard[i, j].name == defFlyingOx
				defFlyingOxMove(i, j, option)
			elseif chessboard[i, j].name == defFlyingStag
				defFlyingStagMove(i, j, option)
			elseif chessboard[i, j].name == defFreeBoar
				defFreeBoarMove(i, j, option)
			elseif chessboard[i, j].name == defFreeEagle
				defFreeEagleMove(i, j, option)
			elseif chessboard[i, j].name == defGoldGeneral
				defGoldGeneralMove(i, j, option)
			elseif chessboard[i, j].name == defGreatGeneral
				defGreatGeneralMove(i, j, option)
			elseif chessboard[i, j].name == defHeavenlyTetrarch
				defHeavenlyTetrarchMove(i, j, option)
			elseif chessboard[i, j].name == defHornedFalcon
				defHornedFalconMove(i, j, option)
			elseif chessboard[i, j].name == defIronGeneral
				defIronGeneralMove(i, j, option)
			elseif chessboard[i, j].name == defKing
				defKingMove(i, j, option)
			elseif chessboard[i, j].name == defKirin
				defKirinMove(i, j, option)
			elseif chessboard[i, j].name == defLance
				defLanceMove(i, j, option)
			elseif chessboard[i, j].name == defLionHawk
				defLionHawkMove(i, j, option)
			elseif chessboard[i, j].name == defLion
				defLionMove(i, j, option)
			elseif chessboard[i, j].name == defMultiGeneral
				defMultiGeneralMove(i, j, option)
			elseif chessboard[i, j].name == defKnight
				defKnightMove(i, j, option)
			elseif chessboard[i, j].name == defPawn
				defPawnMove(i, j, option)
			elseif chessboard[i, j].name == defPhoenix
				defPhoenixMove(i, j, option)
			elseif chessboard[i, j].name == defQueen
				defQueenMove(i, j, option)
			elseif chessboard[i, j].name == defRook
				defRookMove(i, j, option)
			elseif chessboard[i, j].name == defReverseChariot
				defReverseChariotMove(i, j, option)
			elseif chessboard[i, j].name == defRookGeneral
				defRookGeneralMove(i, j, option)
			elseif chessboard[i, j].name == defSilverGeneral
				defGeneralMove(i, j, option)
			elseif chessboard[i, j].name == defSoaringEagle
				defSoaringEagleMove(i, j, option)
			elseif chessboard[i, j].name == defSideMover
				defSideMoverMove(i, j, option)
			elseif chessboard[i, j].name == defSideSoldier
				defSideSoldierMove(i, j, option)
			elseif chessboard[i, j].name == defViceGeneral
				defViceGeneralMove(i, j, option)
			elseif chessboard[i, j].name == defVerticalMover
				defVerticalMoverMove(i, j, option)
			elseif chessboard[i, j].name == defVerticalSoldier
				defVerticalSoldierMove(i, j, option)
			elseif chessboard[i, j].name == defWaterBuffalo
				defWaterBuffaloMove(i, j, option)
			elseif chessboard[i, j].name == defWhale
				defWhaleMove(i, j, option)
			elseif chessboard[i, j].name == defWhiteHorse
				defWhiteHorseMove(i, j, option)
				if chessboard[i, j].name == defBishop
					defBishopMove(i, j, option)
				elseif chessboard[i, j].name == defBishopGeneral
					defBishopGeneralMove(i, j, option)
				elseif chessboard[i, j].name == defBlindTiger
					defBlindTigerMove(i, j, option)
				elseif chessboard[i, j].name == defCopperGeneral
					defCopperGeneralMove(i, j, option)
				elseif chessboard[i, j].name == defChariotSoldier
					defChariotSoldierMove(i, j, option)
				elseif chessboard[i, j].name == defDog
					defDogMove(i, j, option)
				elseif chessboard[i, j].name == defDrunkElephant
					defDrunkElephantrMove(i, j, option)
				elseif chessboard[i, j].name == defDragonHorse
					defDragonHorseMove(i, j, option)
				elseif chessboard[i, j].name == defDragonKing
					defDragonKingMove(i, j, option)
				elseif chessboard[i, j].name == defFerociousLeopard
					defFerociousLeopardMove(i, j, option)
				elseif chessboard[i, j].name == defFireDemon
					defFireDemonMove(i, j, option)
				elseif chessboard[i, j].name == defFlyingOx
					defFlyingOxMove(i, j, option)
				elseif chessboard[i, j].name == defFlyingStag
					defFlyingStagMove(i, j, option)
				elseif chessboard[i, j].name == defFreeBoar
					defFreeBoarMove(i, j, option)
				elseif chessboard[i, j].name == defFreeEagle
					defFreeEagleMove(i, j, option)
				elseif chessboard[i, j].name == defGoldGeneral
					defGoldGeneralMove(i, j, option)
				elseif chessboard[i, j].name == defGreatGeneral
					defGreatGeneralMove(i, j, option)
				elseif chessboard[i, j].name == defHeavenlyTetrarch
					defHeavenlyTetrarchMove(i, j, option)
				elseif chessboard[i, j].name == defHornedFalcon
					defHornedFalconMove(i, j, option)
				elseif chessboard[i, j].name == defIronGeneral
					defIronGeneralMove(i, j, option)
				elseif chessboard[i, j].name == defKing
					defKingMove(i, j, option)
				elseif chessboard[i, j].name == defKirin
					defKirinMove(i, j, option)
				elseif chessboard[i, j].name == defLance
					defLanceMove(i, j, option)
				elseif chessboard[i, j].name == defLionHawk
					defLionHawkMove(i, j, option)
				elseif chessboard[i, j].name == defLion
					defLionMove(i, j, option)
				elseif chessboard[i, j].name == defMultiGeneral
					defMultiGeneralMove(i, j, option)
				elseif chessboard[i, j].name == defKnight
					defKnightMove(i, j, option)
				elseif chessboard[i, j].name == defPawn
					defPawnMove(i, j, option)
				elseif chessboard[i, j].name == defPhoenix
					defPhoenixMove(i, j, option)
				elseif chessboard[i, j].name == defQueen
					defQueenMove(i, j, option)
				elseif chessboard[i, j].name == defRook
					defRookMove(i, j, option)
				elseif chessboard[i, j].name == defReverseChariot
					defReverseChariotMove(i, j, option)
				elseif chessboard[i, j].name == defRookGeneral
					defRookGeneralMove(i, j, option)
				elseif chessboard[i, j].name == defSilverGeneral
					defGeneralMove(i, j, option)
				elseif chessboard[i, j].name == defSoaringEagle
					defSoaringEagleMove(i, j, option)
				elseif chessboard[i, j].name == defSideMover
					defSideMoverMove(i, j, option)
				elseif chessboard[i, j].name == defSideSoldier
					defSideSoldierMove(i, j, option)
				elseif chessboard[i, j].name == defViceGeneral
					defViceGeneralMove(i, j, option)
				elseif chessboard[i, j].name == defVerticalMover
					defVerticalMoverMove(i, j, option)
				elseif chessboard[i, j].name == defVerticalSoldier
					defVerticalSoldierMove(i, j, option)
				elseif chessboard[i, j].name == defWaterBuffalo
					defWaterBuffaloMove(i, j, option)
				elseif chessboard[i, j].name == defWhale
					defWhaleMove(i, j, option)
				elseif chessboard[i, j].name == defWhiteHorse
					defWhiteHorseMove(i, j, option)
				end
			end
		end
	end
end

function update(srcRow::Int64, srcCol::Int64, destRow::Int64, destCol::Int64, option::String)
	global tempChessboard
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377


















378
379
380
381
382
383
384
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
346
347
348
349
350
351
352
353
354
355
356

357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376

















377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401







-
+















+
+






+
+
+
+
+
+
+
+
+



-
+






-
+













-
+


















+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	#	push!(capturedArray, captured.name)
	#	return false
	end
	return false
end

# Copy move into moveChoice if it is better
function demonBurn(destRow::Int64, destCol::Int64, temp::Int64)
function demonBurn(srcRow::Int64, srcCol::Int64, destRow::Int64, destCol::Int64, temp::Int64)
	for i in 1:9
		tempRow = destRow + moveOption[i].row
		tempCol = destCol + moveOption[i].col
		if tempRow <= dim && tempRow >= 1 && tempCol <= dim && tempCol >= 1
			if chessboard[tempRow, tempCol].side != defDummy && chessboard[srcRow, srcCol].side != chessboard[tempRow, tempCol].side
				temp += pieceValTenjiku[chessboard[tempRow, tempCol].name]
			end
		end
	end
	return temp
end

# tempMoveChoice[1] is going to store the type of attack, 1 = single capture, 2 = double capture, 3 = vice general/fire demon
# Have not coded changing capturing chessboard
function capture(tempMoveChoice)
	a = 0
	b = 0
	global strength
	global moveChoice
	temp = -1
	if tempMoveChoice[1] == 1
		a = 4
		b = 5
	elseif tempMoveChoice[1] == 3
		a = 8
		b = 9
		while tempMoveChoice[a] == 0 && tempMoveChoice[b] == 0
			a -= 2
			b -= 2
		end
	end
	if tempMoveChoice[1] == 1 || tempMoveChoice[1] == 3
		if dim == tDim
			temp = pieceValTenjiku[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name] - pieceValTenjiku[chessboard[tempMoveChoice[2], tempMoveChoice[3]].name]
			if chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defFireDemon
				temp = demonBurn(tempMoveChoice[a], tempMoveChoice[b], temp)
				temp = demonBurn(tempMoveChoice[2], tempMoveChoice[3], tempMoveChoice[a], tempMoveChoice[b], temp)
			end		
		elseif dim == cDim
			temp = pieceValChu[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name] - pieceValTenjiku[chessboard[tempMoveChoice[2], tempMoveChoice[3]].name]
		else
			temp = pieceVal[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name] - pieceValTenjiku[chessboard[tempMoveChoice[2], tempMoveChoice[3]].name]
		end
		if chessboard[tempMoveChoice[a], tempMoveChoice[b]].side == defWhite # check if attack is safe
		if chessboard[tempMoveChoice[2], tempMoveChoice[3]].side == defBlack # check if attack is safe
			if chessboard[tempMoveChoice[a], tempMoveChoice[b]].WAttack == 0
				if chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing && dim == tDim
					temp += 600
				elseif chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing && dim == cDim
					temp += 91
				elseif chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing
					temp += 68
				elseif dim == tDim
					temp += 500
				else
					temp += 50
				end
			end
		elseif chessboard[tempMoveChoice[a], tempMoveChoice[b]].side == defBlack
		elseif chessboard[tempMoveChoice[2], tempMoveChoice[3]].side == defWhite
			if chessboard[tempMoveChoice[a], tempMoveChoice[b]].BAttack == 0
				if chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing && dim == tDim
					temp += 600
				elseif chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing && dim == cDim
					temp += 91
				elseif chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing
					temp += 68
				elseif dim == tDim
					temp += 500
				else
					temp += 50
				end
			end
		end
	elseif tempMoveChoice[1] == 2
		a = 4
		b = 5
		while tempMoveChoice[a] != 0 && tempMoveChoice[b] != 0
			if chessboard[tempMoveChoice[a], tempMoveChoice[b]] != defDummy
			if dim == tDim
				if temp == -1
					temp = pieceValTenjiku[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name] - pieceValTenjiku[chessboard[tempMoveChoice[2], tempMoveChoice[3]].name]
				else
					temp += pieceValTenjiku[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name]	
				end
			elseif dim == cDim
				if temp == -1
					temp = pieceValChu[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name] - pieceValTenjiku[chessboard[tempMoveChoice[2], tempMoveChoice[3]].name]
				else
					temp += pieceValChu[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name]
				end
			else
				if temp == -1
					temp = pieceVal[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name] - pieceValTenjiku[chessboard[tempMoveChoice[2], tempMoveChoice[3]].name]
				else
					temp += pieceVal[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name]
				if dim == tDim
					if temp == -1
						temp = pieceValTenjiku[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name] - pieceValTenjiku[chessboard[tempMoveChoice[2], tempMoveChoice[3]].name]
					else
						temp += pieceValTenjiku[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name]	
					end
				elseif dim == cDim
					if temp == -1
						temp = pieceValChu[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name] - pieceValTenjiku[chessboard[tempMoveChoice[2], tempMoveChoice[3]].name]
					else
						temp += pieceValChu[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name]
					end
				else
					if temp == -1
						temp = pieceVal[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name] - pieceValTenjiku[chessboard[tempMoveChoice[2], tempMoveChoice[3]].name]
					else
						temp += pieceVal[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name]
					end
				end
			end
			if tempMoveChoice[a + 2] == 0 && tempMoveChoice[b + 2] == 0
				if chessboard[tempMoveChoice[a], tempMoveChoice[b]].side == defWhite # check if attack is safe
					if chessboard[tempMoveChoice[a], tempMoveChoice[b]].WAttack == 0
						if chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing && dim == tDim
							temp += 600
407
408
409
410
411
412
413
414
415
416
417
418
419
420

421
422
423
424
425

426
427
428
429
430
431
432

433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466


467
468
469
470
471
472
473
474
475

476
477



478
479
480
481
482
483


484
485
486
487
488
489
490
491
492
493

494
495
496
497
498
499
500
501
502
503
504
505
506
507
508


509
510
511
512
513


















514
515
516
517
518
519
520
521
522
523
524


525
526
527
528
529

530
531
532
533
534
535
536

537
538
539




540
541
542
543
544

545
546

547
548
549




550
551
552
553
554
555
556
557
558

559
560
561




562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580

581
582
583
584
585
586
587
424
425
426
427
428
429
430







431





432







433




























434
435
436
437


438
439
440
441
442
443
444
445
446
447
448
449


450
451
452
453
454
455
456
457
458
459
460
461

462
463
464
465
466



467


468
469
470
471
472
473
474
475
476
477
478
479
480
481
482





483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527



528
529
530
531
532
533
534
535

536
537
538
539



540
541
542
543
544
545
546
547
548
549
550
551
552
553



554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575

576
577
578
579
580
581
582
583







-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
+
+









+
-
-
+
+
+






+
+

-





-
-
-
+
-
-













+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+











+
+





+







+
-
-
-
+
+
+
+




-
+


+
-
-
-
+
+
+
+









+
-
-
-
+
+
+
+


















-
+







						end
					end
				end
			end
			a += 2
			b += 2
		end
	elseif tempMoveChoice[1] == 3
		a = 8
		b = 9
		while tempMoveChoice[a] == 0 && tempMoveChoice[b] == 0
			a -= 2
			a -= 2
		end
	end
		if dim == tDim
			temp = pieceValTenjiku[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name] - pieceValTenjiku[chessboard[tempMoveChoice[2], tempMoveChoice[3]].name]
			if chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defFireDemon
				temp = demonBurn(tempMoveChoice[a], tempMoveChoice[b], temp)
			end		
	println(strength)
		elseif dim == cDim
			temp = pieceValChu[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name] - pieceValTenjiku[chessboard[tempMoveChoice[2], tempMoveChoice[3]].name]
		else
			temp = pieceVal[chessboard[tempMoveChoice[a], tempMoveChoice[b]].name] - pieceValTenjiku[chessboard[tempMoveChoice[2], tempMoveChoice[3]].name]
		end
		if chessboard[tempMoveChoice[a], tempMoveChoice[b]].side == defWhite # check if attack is safe
			if chessboard[tempMoveChoice[a], tempMoveChoice[b]].WAttack == 0
	println(tempMoveChoice)
				if chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing && dim == tDim
					temp += 600
				elseif chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing && dim == cDim
					temp += 91
				elseif chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing
					temp += 68
				elseif dim == tDim
					temp += 500
				else
					temp += 50
				end
			end
		elseif chessboard[tempMoveChoice[a], tempMoveChoice[b]].side == defBlack
			if chessboard[tempMoveChoice[a], tempMoveChoice[b]].BAttack == 0
				if chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing && dim == tDim
					temp += 600
				elseif chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing && dim == cDim
					temp += 91
				elseif chessboard[tempMoveChoice[2], tempMoveChoice[3]].name == defKing
					temp += 68
				elseif dim == tDim
					temp += 500
				else
					temp += 50
				end
			end
		end
	end
	if temp > strength
		storeMoveChoice = [tempMoveChoice[2], tempMoveChoice[3], tempMoveChoice[4], tempMoveChoice[5], tempMoveChoice[6], tempMoveChoice[7], tempMoveChoice[8], tempMoveChoice[9]]
		strength = temp
		moveChoice = deepcopy(tempMoveChoice)
		println(strength)
		println(moveChoice)
		#println(strength)
		#println(moveChoice)
	end
end

function step(srcRow::Int64, srcCol::Int64, option::String, destRow::Int64, destCol::Int64)
	if destRow <= dim && destRow >= 1 && destCol <= dim && destCol >= 1
		if option == "update"
			update(srcRow, srcCol, destRow, destCol, option)
		end
		if option == "capture"
			if chessboard[srcRow, srcCol].side != chessboard[destRow, destCol] && chessboard[destRow, destCol].side != defDummy
			tempMoveChoice = [1, srcRow, srcCol, destRow, destCol, 0, 0, 0, 0]
			capture(tempMoveChoice)
				tempMoveChoice = [1, srcRow, srcCol, destRow, destCol, 0, 0, 0, 0]
				capture(tempMoveChoice)
			end
		end
	end
end

function stepMultiple(srcRow::Int64, srcCol::Int64, option::String, tempRow::Int64, tempCol::Int64, jumps::Int64, tempMoveChoice)
	global tempChessboard
	a = 0
	b = 0
	if jumps == 0
		println("return")
		return
	end
	saveMoveChoice = deepcopy(tempMoveChoice)
	for i in 1:9
		if (chessboard[srcRow, srcCol].name == defFreeEagle && (i == 1 || i == 3 || i == 7 || i == 9)) || (chessboard[srcRow, srcCol].name != defFreeEagle && i != 5)
			println(tempMoveChoice)
			println("temp")
			tempMoveChoice = saveMoveChoice
			tempMoveChoice = deepcopy(saveMoveChoice)
			println(saveMoveChoice)
			println("save")
			newTempRow = tempRow + moveOption[i].row
			newTempCol = tempCol + moveOption[i].col
			if newTempRow <= dim && newTempRow >= 1 && newTempCol <= dim && newTempCol >= 1
				if option == "special update" || option == "demon update"
					update(srcRow, srcCol, newTempRow, newTempCol, option)
				end
				if option == "capture"
					a = 4
					b = 5
					while tempMoveChoice[a] != 0 && tempMoveChoice[b] != 0
						a += 2
						b += 2
					end
					if tempMoveChoice[1] == 2
						if (a == 4 && b == 5 && chessboard[srcRow, srcCol].side != chessboard[newTempRow, newTempCol].side && chessboard[newTempRow, newTempCol].side != defDummy)
					tempMoveChoice[a] = newTempRow
					tempMoveChoice[b] = newTempCol
					capture(tempMoveChoice)
				end
				if chessboard[srcRow, srcCol].name == defLion || chessboard[srcRow, srcCol].name == defLionHawk
							tempMoveChoice[a] = newTempRow
							tempMoveChoice[b] = newTempCol
							capture(tempMoveChoice)
						elseif a == 6 && b == 7 && (chessboard[srcRow, srcCol].side != chessboard[tempMoveChoice[4], tempMoveChoice[5]].side && chessboard[tempMoveChoice[4], tempMoveChoice[5]].side != defDummy) || (chessboard[srcRow, srcCol].side != chessboard[newTempRow, newTempCol].side && chessboard[newTempRow, newTempCol].side != defDummy)
							tempMoveChoice[a] = newTempRow
							tempMoveChoice[b] = newTempCol
							capture(tempMoveChoice)
						end
					end
					if tempMoveChoice[1] == 3
						if chessboard[srcRow, srcCol].side != chessboard[tempMoveChoice[a], tempMoveChoice[b]].side && chessboard[tempMoveChoice[a], tempMoveChoice[b]].side != defDummy
							tempMoveChoice[a] = newTempRow
							tempMoveChoice[b] = newTempCol
							capture(tempMoveChoice)
						end
					end
				end
				if (chessboard[srcRow, srcCol].name == defLion || chessboard[srcRow, srcCol].name == defLionHawk) && chessboard[srcRow, srcCol].side != chessboard[newTempRow, newTempCol].side
					stepMultiple(srcRow, srcCol, option, newTempRow, newTempCol, jumps - 1, tempMoveChoice)
				elseif chessboard[newTempRow, newTempCol].side == defDummy
					stepMultiple(srcRow, srcCol, option, newTempRow, newTempCol, jumps - 1, tempMoveChoice)
				end
			end
		end
	end
end

function stepMultipleLinear(srcRow::Int64, srcCol::Int64, option::String, tempRow::Int64, tempCol::Int64, jumps::Int64, index::Int64, tempMoveChoice)
	global tempChessboard
	a = 0
	b = 0
	if jumps == 0
		return
	end
	saveMoveChoice = deepcopy(tempMoveChoice)
	if jumps == 2
		tempMoveChoice = deepcopy(saveMoveChoice)
		newTempRow = tempRow + moveOption[index].row
		newTempCol = tempCol + moveOption[index].col
		if newTempRow <= dim && newTempRow >= 1 && newTempCol <= dim && newTempCol >= 1
			if option == "special update" || option == "demon update" || option == "update"
				update(srcRow, srcCol, newTempRow, newTempCol, option)
			end
			if option == "capture"
				if chessboard[srcRow, srcCol].side != chessboard[newTempRow, newTempCol].side && chessboard[newTempRow, newTempCol].side != defDummy
				tempMoveChoice[4] = newTempRow
				tempMoveChoice[5] = newTempCol
				capture(tempMoveChoice)
					tempMoveChoice[4] = newTempRow
					tempMoveChoice[5] = newTempCol			
					capture(tempMoveChoice)
				end
			end
			stepMultipleLinear(srcRow, srcCol, option, newTempRow, newTempCol, jumps - 1, index, tempMoveChoice)
		end
	elseif jumps == 1
		newTempRow = tempRow - moveOption[index].row ## igui
		newTempRow = tempRow - moveOption[index].row # igui
		newTempCol = tempCol - moveOption[index].col
			if option == "capture"
				if (chessboard[srcRow, srcCol].side != chessboard[tempMoveChoice[4], tempMoveChoice[5]].side && chessboard[tempMoveChoice[4], tempMoveChoice[5]].side != defDummy) # Check if either has occupied piece.
				tempMoveChoice[6] = newTempRow
				tempMoveChoice[7] = newTempCol
				capture(tempMoveChoice)
					tempMoveChoice[6] = newTempRow
					tempMoveChoice[7] = newTempCol
					capture(tempMoveChoice)
				end
			end
		if chessboard[srcRow, srcCol].name != defHeavenlyTetrarch
			newTempRow = tempRow + moveOption[index].row
			newTempCol = tempCol + moveOption[index].col
			if newTempRow <= dim && newTempRow >= 1 && newTempCol <= dim && newTempCol >= 1
				if option == "update"
					update(srcRow, srcCol, newTempRow, newTempCol, option)
				end
				if option == "capture"
					if (chessboard[srcRow, srcCol].side != chessboard[tempMoveChoice[4], tempMoveChoice[5]].side && chessboard[tempMoveChoice[4], tempMoveChoice[5]].side != defDummy) || (chessboard[srcRow, srcCol].side != chessboard[newTempRow, newTempCol].side && chessboard[newTempRow, newTempCol].side != defDummy)
					tempMoveChoice[6] = newTempRow
					tempMoveChoice[7] = newTempCol
					capture(tempMoveChoice)
						tempMoveChoice[6] = newTempRow
						tempMoveChoice[7] = newTempCol
						capture(tempMoveChoice)	
					end
				end
			end
		end
	end
end
	
function rangeJump(srcRow::Int64, srcCol::Int64, option::String, index::Int64)
	tempRow = srcRow
	tempCol = srcCol
	while true
		tempRow = tempRow + moveOption[index].row
		tempCol = tempCol + moveOption[index].col
		if tempRow > dim || tempRow < 1 || tempCol > dim || tempCol < 1
			break
		end
		if option == "update" || option == "special update"
			update(srcRow, srcCol, tempRow, tempCol, option)
		end
		if chessboard[tempRow, tempCol].side != defDummy
		if chessboard[srcRow, srcCol].side != chessboard[tempRow, tempCol] && chessboard[tempRow, tempCol].side != defDummy
			if option == "capture"
				tempMoveChoice = [1, srcRow, srcCol, tempRow, tempCol, 0, 0, 0, 0]
				capture(tempMoveChoice)
			end
		end	
		if rangeJumpPriority[chessboard[srcRow, srcCol].name] < rangeJumpPriority[chessboard[tempRow, tempCol].name] # Not jumpable
			break
599
600
601
602
603
604
605

606
607



608
609
610
611
612
613
614
595
596
597
598
599
600
601
602


603
604
605
606
607
608
609
610
611
612







+
-
-
+
+
+







			break
		end
		if option == "update" || option == "special update" || option == "demon update"
			update(srcRow, srcCol, newTempRow, newTempCol, option)
		end
		if chessboard[newTempRow, newTempCol].side != defDummy
			if option == "capture"
				if chessboard[srcRow, srcCol].side != chessboard[tempRow, tempCol] && chessboard[tempRow, tempCol].side != defDummy
				tempMoveChoice = [1, srcRow, srcCol, tempRow, tempCol, 0, 0, 0, 0]
				capture(tempMoveChoice)
					tempMoveChoice = [1, srcRow, srcCol, tempRow, tempCol, 0, 0, 0, 0]
					capture(tempMoveChoice)
				end
			end
			break
		end
	end
end

function defKingMove(srcRow::Int64, srcCol::Int64, option::String)
1312
1313
1314
1315
1316
1317
1318
1319


1320

1321

1322
1323
1310
1311
1312
1313
1314
1315
1316

1317
1318
1319
1320
1321
1322
1323
1324







-
+
+

+

+


	else
		return false
	end
	return false
end

createBoard()
add(7, 8, "lion", "Bl")
add(7, 8, "vice general", "Bl")
add(8, 8, "pawn", "Bl")
printBoard()
currTurn = "Bl"
moveFunctions("capture")
moveFunctions("update")
strength = -1
printBoardBAttack()