Artifact [f54ab3a34f]

Artifact f54ab3a34fddaed307abf7c47130f98bae0b377c:


# 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 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 pieceVal = Dict{String,Int64}("_" => 0, "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",
 	"blind tiger promoted" => "flying stag", "chariot soldier promoted" => "heavenly tetrarch", "copper general promoted" => "side mover", "dog promoted" => "multi general",
  "dragon horse promoted" => "horned falcon", "dragon king promoted" => "soaring eagle", "drunk elephant promoted" => "king", "ferocious leopard promoted" => "bishop", 
  "go between promomted" => "drunk elephant", "gold general promoted" => "rook", "horned falcon promoted" => "bishop general", "iron general promoted" => "vertical soldier", "kirin promoted" => "lion",
  "knight promoted" => "side soldier", "lance promoted" => "white horse", "lion promoted" => "lion hawk", "pawn promoted" => "gold general", "phoenix promoted" => "queen", "queen promoted" => "free eagle",
  "reverse chariot promoted" => "whale", "rook promoted" => "dragon king", "rook general promoted" => "great general", "side mover promoted" => "free boar",
  "side soldier promoted" => "water buffalo", "silver general promoted" => "vertical mover", "soaring eagle promoted" => "rook general", "vertical mover promoted" => "flying ox",
  "vertical soldier promoted" => "chariot soldier", "water buffalo promoted" => "fire demon"  )

global defEmpty = "_"
global defBishop = "bishop"
global defBishopGeneral = "bishop general"
global defBlindTiger = "blind tiger"
global defCopperGeneral = "copper general"
global defChariotSoldier = "chariot soldier"
global defDog = "dog"
global defDrunkElephant = "drunk elephant"
global defDragonHorse = "dragon horse"
global defDragonKing = "dragon king"
global defFerociousLeopard = "ferocious leopard"
global defFlyingOx = "flying ox"
global defFlyingStag = "flying stag"
global defFireDemon = "fire demon"
global defFreeBoar = "free boar"
global defFreeEagle = "free eagle"
global defGoBetween = "go between"
global defGoldGeneral = "gold general"
global defGreatGeneral = "great general"
global defHeavenlyTetrarch = "heavenly tetrarch"
global defHornedFalcon = "horned falcon"
global defIronGeneral = "iron general"
global defKing = "king"
global defKirin = "kirin"
global defLance = "lance"
global defLionHawk = "lion hawk"
global defLion = "lion"
global defMultiGeneral = "multi general"
global defKnight = "knight"
global defPawn = "pawn"
global defPhoenix = "phoenix"
global defQueen = "queen"
global defRook = "rook"
global defReverseChariot = "reverse chariot"
global defRookGeneral = "rook general"
global defSilverGeneral = "silver general"
global defSoaringEagle = "soaring eagle"
global defSideMover = "side mover"
global defSideSoldier = "side soldier"
global defViceGeneral = "vice general"
global defVerticalMover = "vertical mover"
global defVerticalSoldier = "vertical soldier"
global defWaterBuffalo = "water buffalo"
global defWhale = "whale"
global defWhiteHorse = "white horse"


global defDummy = "D"
global defWhite = "Wh"
global defBlack = "Bl"

global tDim = 16
global cDim = 12
global sDim = 9
global mDim = 5
global dim = 16

global moveChoice = Array{Int64}(8)
#global tempMoveChoice1 = Array{Int64}(8)
#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
	name::String
	side::AbstractString
	BAttack::Int
	WAttack::Int
	promote::Bool
end

moveOption = Array{moveOffset}(17)

moveOption[1] = moveOffset(-1, -1)
moveOption[2] = moveOffset(-1, 0)
moveOption[3] = moveOffset(-1, 1)
moveOption[4] = moveOffset(0, -1)
moveOption[5] = moveOffset(0, 0)
moveOption[6] = moveOffset(0, 1)
moveOption[7] = moveOffset(1, -1)
moveOption[8] = moveOffset(1, 0)
moveOption[9] = moveOffset(1, 1)
moveOption[10] = moveOffset(-2, -1)
moveOption[11] = moveOffset(-2, 1)
moveOption[12] = moveOffset(2, -1)
moveOption[13] = moveOffset(2, 1)
moveOption[14] = moveOffset(-1, -2)
moveOption[15] = moveOffset(-1, 2)
moveOption[16] = moveOffset(1, -2)
moveOption[17] = moveOffset(1, 2)

function moveFunctions(option::String)
	global chessboard
	if option == "update"
		for i in 1:dim
			for j in 1:dim
				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)
				end
			end
		end
	end
end

function update(srcRow::Int64, srcCol::Int64, destRow::Int64, destCol::Int64, option::String)
	global tempChessboard
	global chessboard
	if option == "demon update"
		for i in 1:9
			if i != 5
				tempRow = destRow + moveOption[i].row
				tempCol = destCol + moveOption[i].col
				if chessboard[srcRow, srcCol].side == defWhite
					tempChessboard[destRow, destCol].WAttack += 1
					if tempRow <= dim && tempRow >= 1 && tempCol <= dim && tempCol >= 1
						tempChessboard[destRow + moveOption[i].row, destCol + moveOption[i].col].WAttack += 1
					end
				elseif chessboard[srcRow, srcCol].side == defBlack
					tempChessboard[destRow, destCol].BAttack += 1
					if tempRow <= dim && tempRow >= 1 && tempCol <= dim && tempCol >= 1
						tempChessboard[destRow + moveOption[i].row, destCol + moveOption[i].col].BAttack += 1
					end
				end
			end
		end
	elseif option == "special update"
		if chessboard[srcRow, srcCol].side == defWhite
			tempChessboard[destRow, destCol].WAttack += 1
		elseif chessboard[srcRow, srcCol].side == defBlack
			tempChessboard[destRow, destCol].BAttack += 1
		end
	elseif option == "update"
		if chessboard[srcRow, srcCol].side == defWhite
			chessboard[destRow, destCol].WAttack += 1
		elseif chessboard[srcRow, srcCol].side == defBlack
			chessboard[destRow, destCol].BAttack += 1
		end
	end
end

function movePiece(srcRow::Int64, srcCol::Int64, destRow::Int64, destCol::Int64)
	pieceToMove = chessboard[srcRow, srcCol].name
	pieceToMoveSide = chessboard[srcRow, srcCol].side
	pieceAttacked = chessboard[destRow, destCol].name
	if pieceAttacked != pieceToMove || pieceAttack != defDummy
		gamewin = capturePiece(destRow, destCol)
	end
	add(destRow, destCol, pieceToMove, pieceToMoveSide)
	delete(srcRow, srcCol)
	return gamewin
end

function capturePiece(destRow::Int64, destCol::Int64)
	captured = chessboard[destRow, destCol]
	if captured.side == defBlack
		capturedArray = whitePrison # Record which side the piece is on being captured, prison is the colour of where drop can check from
	elseif captured.side == defWhite # Use splice!(array, object) splice returns the object that is removed
		capturedArray = blackPrison
	end
	if captured.name == defKing # gamewin
		push!(capturedArray, captured.name)
		return true
	elseif captured.name == defGGen # Does not promote
		push!(capturedArray, captured.name)
		return false
	#elseif 65 <= UInt32(captured.name) <= 90
	#	captured.name += 32 # Demote captured piece.
	#	push!(capturedArray, captured.name)
	#	return false
	end
	return false
end

# Copy move into moveChoice if it is better
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, demonBurnVal::Int64)
	a = 0
	b = 0
	global strength
	global moveChoice
	global chessboard
	temp = -1
	if demonBurnVal != 0
		temp = demonBurnVal
	end
	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]		
		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[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[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
		local tempChessboard = deepcopy(chessboard)
		while tempMoveChoice[a] != 0 && tempMoveChoice[b] != 0
			if chessboard[tempMoveChoice[a], tempMoveChoice[b]] != defDummy && chessboard[tempMoveChoice[2], tempMoveChoice[3]].side != chessboard[tempMoveChoice[a], tempMoveChoice[b]].side
				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
			testMove(tempMoveChoice[a-2], tempMoveChoice[b-2], tempMoveChoice[a], tempMoveChoice[b])
			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
						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
			a += 2
			b += 2
		end
		chessboard = tempChessboard # restore
	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)
	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" || option == "special update"
			update(srcRow, srcCol, destRow, destCol, option)
		end
		if option == "capture"
			if chessboard[srcRow, srcCol].side != chessboard[destRow, destCol].side && chessboard[destRow, destCol].side != defDummy
				tempMoveChoice = [1, srcRow, srcCol, destRow, destCol, 0, 0, 0, 0]
				capture(tempMoveChoice, 0)
			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
		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)
			tempMoveChoice = deepcopy(saveMoveChoice)
			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, 0)
						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, 0)
						end
					end
					if tempMoveChoice[1] == 3
						temp = 0
						if chessboard[srcRow, srcCol].name == defFireDemon
							temp = demonBurn(srcRow, srcCol, newTempRow, newTempCol, temp)
						end
						if (chessboard[srcRow, srcCol].side != chessboard[newTempRow, newTempCol].side && chessboard[newTempRow, newTempCol].side != defDummy) || temp != 0
							tempMoveChoice[a] = newTempRow
							tempMoveChoice[b] = newTempCol
							capture(tempMoveChoice, temp)
						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, 0)
				end
			end
			stepMultipleLinear(srcRow, srcCol, option, newTempRow, newTempCol, jumps - 1, index, tempMoveChoice)
		end
	elseif jumps == 1
		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, 0)
				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, 0)	
					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[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, 0)
			end
		end	
		if rangeJumpPriority[chessboard[srcRow, srcCol].name] < rangeJumpPriority[chessboard[tempRow, tempCol].name] # Not jumpable
			break
		end	
	end
end

function range(srcRow::Int64, srcCol::Int64, option::String, tempRow::Int64, tempCol::Int64, index::Int64)	
	newTempRow = tempRow
	newTempCol = tempCol
	while true
		newTempRow = newTempRow + moveOption[index].row
		newTempCol = newTempCol + moveOption[index].col
		if newTempRow > dim || newTempRow < 1 || newTempCol > dim || newTempCol < 1
			break
		end
		if option == "update" || option == "special update" || option == "demon update"
			update(srcRow, srcCol, newTempRow, newTempCol, option)
		end
		temp = 0
		if chessboard[srcRow, srcCol].name == defFireDemon
			temp = demonBurn(srcRow, srcCol, newTempRow, newTempCol, temp)
		end
		if chessboard[newTempRow, newTempCol].side != defDummy
			if option == "capture"
				if (chessboard[srcRow, srcCol].side != chessboard[tempRow, tempCol] && chessboard[tempRow, tempCol].side != defDummy) || temp != 0
					tempMoveChoice = [1, srcRow, srcCol, tempRow, tempCol, 0, 0, 0, 0]
					capture(tempMoveChoice, temp)
				end
			end
			break
		end
	end
end

function defKingMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i != 5
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defDrunkElephantMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if chessboard[srcRow, srcCol].side == defWhite && (i != 5 && i != 8) || chessboard[srcRow, srcCol].side == defBlack && (i != 2 && i != 5)
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defViceGeneralMove(srcRow::Int64, srcCol::Int64, option::String)
	global tempChessboard
	if option == "update"
		option = "special update"
		tempChessboard = deepcopy(chessboard)
		for i in 1:dim
			for j in 1:dim
				tempChessboard[i, j].WAttack = 0
				tempChessboard[i, j].BAttack = 0
			end
		end
	end
	for i in 1:9
		if i == 1 || i == 3 || i == 7 || i == 9
			rangeJump(srcRow, srcCol, option, i)
		end
	end
	tempMoveChoice = [3, srcRow, srcCol, 0, 0, 0, 0, 0, 0]
	stepMultiple(srcRow, srcCol, option, srcRow, srcCol, 3, tempMoveChoice)
	if option == "special update"
		for i in 1:dim
			for j in 1:dim
				if i == srcRow && j == srcCol
				elseif chessboard[srcRow, srcCol].side == defWhite && tempChessboard[i, j].WAttack >= 1
					chessboard[i, j].WAttack += 1
				elseif chessboard[srcRow, srcCol].side == defBlack && tempChessboard[i, j].BAttack >= 1
					chessboard[i, j].BAttack += 1
				end
			end
		end
	end
end
	
function defGreatGeneralMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i != 5
			rangeJump(srcRow, srcCol, option, i)
		end
	end
end

function defBishopGeneralMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 1 || i == 3 || i == 7 || i == 9
			rangeJump(srcRow, srcCol, option, i)
		end
	end
end

function defRookGeneralMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 2 || i == 4 || i == 6 || i == 8
			rangeJump(srcRow, srcCol, option, i)
		end
	end
end

function defHornedFalconMove(srcRow::Int64, srcCol::Int64, option::String)
	global tempChessboard
	if option == "update"
		option = "special update"
		tempChessboard = deepcopy(chessboard)
		for i in 1:dim
			for j in 1:dim
				tempChessboard[i, j].WAttack = 0
				tempChessboard[i, j].BAttack = 0
			end
		end
	end
	for i in 1:9
		if i != 5 && ((chessboard[srcRow, srcCol].side == defWhite && i != 2) || (chessboard[srcRow, srcCol].side == defBlack && i != 8))
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		elseif (chessboard[srcRow, srcCol].side == defWhite && i == 2) || (chessboard[srcRow, srcCol].side == defBlack && i == 8)
			tempMoveChoice = [2, srcRow, srcCol, 0, 0, 0, 0, 0, 0]
			stepMultipleLinear(srcRow, srcCol, option, srcRow, srcCol, 2, i, tempMoveChoice)
			step(srcRow, srcCol, option, srcRow + 2*moveOption[i].row, srcCol + 2*moveOption[i].col)
		end
	end
	if option == "special update"
		for i in 1:dim
			for j in 1:dim
				if i == srcRow && j == srcCol
				elseif chessboard[srcRow, srcCol].side == defWhite && tempChessboard[i, j].WAttack >= 1
					chessboard[i, j].WAttack += 1
				elseif chessboard[srcRow, srcCol].side == defBlack && tempChessboard[i, j].BAttack >= 1
					chessboard[i, j].BAttack += 1
				end
			end
		end
	end
end

function defSoaringEagleMove(srcRow::Int64, srcCol::Int64, option::String)
	global tempChessboard
	if option == "update"
		option = "special update"
		tempChessboard = deepcopy(chessboard)
		for i in 1:dim
			for j in 1:dim
				tempChessboard[i, j].WAttack = 0
				tempChessboard[i, j].BAttack = 0
			end
		end
	end
	for i in 1:9
		if i != 5 && ((chessboard[srcRow, srcCol].side == defWhite && i != 1 && i != 3) || (chessboard[srcRow, srcCol].side == defBlack && i != 7 && i != 9))
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		elseif (chessboard[srcRow, srcCol].side == defWhite && (i == 1 || i == 3)) || (chessboard[srcRow, srcCol].side == defBlack && (i == 7 || i == 9))
			tempMoveChoice = [2, srcRow, srcCol, 0, 0, 0, 0, 0, 0]
			stepMultipleLinear(srcRow, srcCol, option, srcRow, srcCol, 2, i, tempMoveChoice)
			step(srcRow, srcCol, option, srcRow + 2*moveOption[i].row, srcCol + 2*moveOption[i].col)
		end
	end
	if option == "special update"
		for i in 1:dim
			for j in 1:dim
				if i == srcRow && j == srcCol
				elseif chessboard[srcRow, srcCol].side == defWhite && tempChessboard[i, j].WAttack >= 1
					chessboard[i, j].WAttack += 1
				elseif chessboard[srcRow, srcCol].side == defBlack && tempChessboard[i, j].BAttack >= 1
					chessboard[i, j].BAttack += 1
				end
			end
		end
	end
end

function defDragonHorseMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 1 || i == 3 || i == 7 || i == 9
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		elseif i == 2 || i == 4 || i == 6 || i == 8
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defDragonKingMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 2 || i == 4 || i == 6 || i == 8 
			range(srcRow, srcCol, srcRow, srcCol, option, i)
		elseif i == 1 || i == 3 || i == 7 || i == 9
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end
		
function defBishopMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 1 || i == 3 || i == 7 || i == 9
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		end
	end
end

function defRookMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 2 || i == 4 || i == 6 || i == 8 
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		end
	end
end

function defFerociousLeopardMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i != 4 && i != 5 && i != 6
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defGoldGeneralMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if (chessboard[srcRow, srcCol].side == defWhite && (i != 5 && i != 7 && i != 9)) || (chessboard[srcRow, srcCol].side == defBlack && (i != 1 && i != 3 && i != 5))
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defPawnMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if (chessboard[srcRow, srcCol].side == defWhite && i == 2) || (chessboard[srcRow, srcCol].side == defBlack && i == 8)
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defFireDemonMove(srcRow::Int64, srcCol::Int64, option::String)
	global tempChessboard
	if option == "update" || option == "capture"
		if option == "update"
			option = "demon update"
		end
		tempChessboard = deepcopy(chessboard)
		for i in 1:dim
			for j in 1:dim
				tempChessboard[i, j].WAttack = 0
				tempChessboard[i, j].BAttack = 0
			end
		end
	end
	for i in 1:9
		if i != 2 && i != 5 && i != 8
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		end
	end
	tempMoveChoice = [3, srcRow, srcCol, 0, 0, 0, 0, 0, 0]
	stepMultiple(srcRow, srcCol, option, srcRow, srcCol, 3, tempMoveChoice)
	if option == "demon update"
		for i in 1:dim
			for j in 1:dim
				if i == srcRow && j == srcCol
				elseif chessboard[srcRow, srcCol].side == defWhite && tempChessboard[i, j].WAttack >= 1
					chessboard[i, j].WAttack += 1
				elseif chessboard[srcRow, srcCol].side == defBlack && tempChessboard[i, j].BAttack >= 1
					chessboard[i, j].BAttack += 1
				end
			end
		end
	end
end

function defHeavenlyTetrarchMove(srcRow::Int64, srcCol::Int64, option::String) # Need Exceptions
	for i in 1:9
		if i != 5
			tempMoveChoice = [2, srcRow, srcCol, 0, 0, 0, 0, 0, 0]
			stepMultipleLinear(srcRow, srcCol, option, srcRow, srcCol, 2, i, tempMoveChoice)
		end
		if i != 4 && i != 5 && i != 6
			range(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col, i)
		elseif i == 4 || i == 6
			tempRow = srcRow + 2*moveOption[i].row
			tempCol = srcCol + 2*moveOption[i].col
			step(srcRow, srcCol, option, tempRow, tempCol)
			if tempRow <= dim && tempRow >= 1 && tempCol <= dim && tempCol >= 1
				if chessboard[tempRow, tempCol].side == defDummy
					step(srcRow, srcCol, option, srcRow + 3*moveOption[i].row, srcCol + 3*moveOption[i].col)
				end
			end
		end
	end
end
			
function defWaterBuffaloMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i != 2 && i != 5 && i != 8
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		elseif i == 2 || i == 8
			tempRow = srcRow + moveOption[i].row
			tempCol = srcCol + moveOption[i].col
			step(srcRow, srcCol, option, tempRow, tempCol)
			if tempRow <= dim && tempRow >= 1 && tempCol <= dim && tempCol >= 1
				if chessboard[tempRow, tempCol].side == defDummy
					step(srcRow, srcCol, option, srcRow + 2*moveOption[i].row, srcCol + 2*moveOption[i].col)
				end
			end
		end
	end
end

function defChariotSoldierMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i != 4 && i != 5 && i != 6
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		elseif i == 4 || i == 6
			tempRow = srcRow + moveOption[i].row
			tempCol = srcCol + moveOption[i].col
			step(srcRow, srcCol, option, tempRow, tempCol)
			if tempRow <= dim && tempRow >= 1 && tempCol <= dim && tempCol >= 1
				if chessboard[tempRow, tempCol].side == defDummy
					step(srcRow, srcCol, option, srcRow + 2*moveOption[i].row, srcCol + 2*moveOption[i].col)
				end
			end
		end
	end
end

function defSideSoldierMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 4 || i == 6
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		elseif i == 2 || i == 8
			tempRow = srcRow + moveOption[i].row
			tempCol = srcCol + moveOption[i].col
			step(srcRow, srcCol, option, tempRow, tempCol)
			if tempRow <= dim && tempRow >= 1 && tempCol <= dim && tempCol >= 1
				if chessboard[tempRow, tempCol].side == defDummy && ((chessboard[srcRow, srcCol].side == defWhite && i == 2) || (chessboard[srcRow, srcCol].side == defBlack && i == 8))
					step(srcRow, srcCol, option, srcRow + 2*moveOption[i].row, srcCol + 2*moveOption[i].col)
				end
			end
		end
	end
end
			
function defVerticalSoldierMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if (chessboard[srcRow, srcCol].side == defWhite && i == 2) || (chessboard[srcRow, srcCol].side == defBlack && i == 8)
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		elseif i == 4 || i == 6 || i == 8
			tempRow = srcRow + moveOption[i].row
			tempCol = srcCol + moveOption[i].col
			step(srcRow, srcCol, option, tempRow, tempCol)
			if tempRow <= dim && tempRow >= 1 && tempCol <= dim && tempCol >= 1
				if chessboard[tempRow, tempCol].side == defDummy && (i == 4 || i == 6)
					step(srcRow, srcCol, option, srcRow + 2*moveOption[i].row, srcCol + 2*moveOption[i].col)
				end
			end
		end
	end
end

function defKnightMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 10:13
		if (chessboard[srcRow, srcCol].side == defWhite && (i == 10 || i == 11)) || (chessboard[srcRow, srcCol].side == defBlack && (i == 12 || i == 13))
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defIronGeneralMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if (chessboard[srcRow, srcCol].side == defWhite && (i == 1 || i == 2 || i == 3)) || (chessboard[srcRow, srcCol].side == defBlack && (i == 7 || i == 8 || i == 9))
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defFreeEagleMove(srcRow::Int64, srcCol::Int64, option::String) # Need Exceptions
	global tempChessboard
	if option == "update"
		option = "special update"
		tempChessboard = deepcopy(chessboard)
		for i in 1:dim
			for j in 1:dim
				tempChessboard[i, j].WAttack = 0
				tempChessboard[i, j].BAttack = 0
			end
		end
	end
	tempMoveChoice = [2, srcRow, srcCol, 0, 0, 0, 0, 0, 0]
	stepMultiple(srcRow, srcCol, option, srcRow, srcCol, 2, tempMoveChoice)
	for i in 1:9
		if i != 5
			step(srcRow, srcCol, option, srcRow + 2*moveOption[i].row, srcCol + 2*moveOption[i].col)
			range(srcRow, srcCol, option, srcRow, srcCol, i)		
		end
	end
	if option == "special update"
		for i in 1:dim
			for j in 1:dim
				if i == srcRow && j == srcCol
				elseif chessboard[srcRow, srcCol].side == defWhite && tempChessboard[i, j].WAttack >= 1
					chessboard[i, j].WAttack += 1
				elseif chessboard[srcRow, srcCol].side == defBlack && tempChessboard[i, j].BAttack >= 1
					chessboard[i, j].BAttack += 1
				end
			end
		end
	end
end

	

function defLionHawkMove(srcRow::Int64, srcCol::Int64, option::String)
	global tempChessboard
	if option == "update"
		option = "special update"
		tempChessboard = deepcopy(chessboard)
		for i in 1:dim
			for j in 1:dim
				tempChessboard[i, j].WAttack = 0
				tempChessboard[i, j].BAttack = 0
			end
		end
	end
	tempMoveChoice = [2, srcRow, srcCol, 0, 0, 0, 0, 0, 0]
	stepMultiple(srcRow, srcCol, option, srcRow, srcCol, 2, tempMoveChoice)
	for i in 1:17
		if i >= 1 && i <= 9 && i != 5
			step(srcRow, srcCol, option, srcRow + 2*moveOption[i].row, srcCol + 2*moveOption[i].col)
		elseif i >= 10 && i <= 17
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
		if i == 1 || i == 3 || i == 7 || i == 9
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		end
	end
	if option == "special update"
		for i in 1:dim
			for j in 1:dim
				if i == srcRow && j == srcCol
				elseif chessboard[srcRow, srcCol].side == defWhite && tempChessboard[i, j].WAttack >= 1
					chessboard[i, j].WAttack += 1
				elseif chessboard[srcRow, srcCol].side == defBlack && tempChessboard[i, j].BAttack >= 1
					chessboard[i, j].BAttack += 1
				end
			end
		end
	end
end


function defQueenMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i != 5
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		end
	end
end

function defLionMove(srcRow::Int64, srcCol::Int64, option::String)
	global tempChessboard
	if option == "update"
		option = "special update"
		tempChessboard = deepcopy(chessboard)
		for i in 1:dim
			for j in 1:dim
				tempChessboard[i, j].WAttack = 0
				tempChessboard[i, j].BAttack = 0
			end
		end
	end
	tempMoveChoice = [2, srcRow, srcCol, 0, 0, 0, 0, 0, 0]
	stepMultiple(srcRow, srcCol, option, srcRow, srcCol, 2, tempMoveChoice)
	for i in 1:17
		if i >= 1 && i <= 9 && i != 5
			step(srcRow, srcCol, option, srcRow + 2*moveOption[i].row, srcCol + 2*moveOption[i].col)
		elseif i >= 10 && i <= 17
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
	if option == "special update"
		for i in 1:dim
			for j in 1:dim
				if i == srcRow && j == srcCol
				elseif chessboard[srcRow, srcCol].side == defWhite && tempChessboard[i, j].WAttack >= 1
					chessboard[i, j].WAttack += 1
				elseif chessboard[srcRow, srcCol].side == defBlack && tempChessboard[i, j].BAttack >= 1
					chessboard[i, j].BAttack += 1
				end
			end
		end
	end
end

function defPhoenixMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 2 || i == 4 || i == 6 || i == 8
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		elseif i == 1 || i == 3 || i == 7 || i == 9
			step(srcRow, srcCol, option, srcRow + 2*moveOption[i].row, srcCol + 2*moveOption[i].col)
		end
	end
end

function defKirinMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 1 || i == 3 || i == 7 || i == 9
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		elseif i == 2 || i == 4 || i == 6 || i == 8
			step(srcRow, srcCol, option, srcRow + 2*moveOption[i].row, srcCol + 2*moveOption[i].col)
		end
	end
end

function defFreeBoarMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i != 2 && i != 5 && i != 8
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		end
	end
end

function defFlyingOxMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i != 4 && i != 5 && i != 6
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		end
	end
end

function defSideMoverMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 4 || i == 6
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		elseif i == 2 || i == 8
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defVerticalMoverMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 2 || i == 8
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		elseif i == 4 || i == 6
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defCopperGeneralMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 2 || i == 8 || (chessboard[srcRow, srcCol].side == defWhite && (i == 1 || i == 3)) || (chessboard[srcRow, srcCol].side == defBlack && (i == 7 || i == 9))
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defSilverGeneralMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if (i != 4 && i != 5 && i != 6) || (chessboard[srcRow, srcCol].side == defWhite && i != 8) || (chessboard[srcRow, srcCol].side == defBlack && i != 2)
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defMultiGeneralMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if (chessboard[srcRow, srcCol].side == defWhite && (i == 2 || i == 7 || i == 9)) || (chessboard[srcRow, srcCol].side == defBlack && (i == 1 || i == 3 || i == 8))
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		end
	end
end

function defFlyingStagMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 2 || i == 8
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		elseif i != 5
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defDogMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if (chessboard[srcRow, srcCol].side == defWhite && (i == 2 || i == 7 || i == 9)) || (chessboard[srcRow, srcCol].side == defBlack && (i == 1 || i == 3 || i == 8))
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end
		
function defBlindTigerMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i != 5 && ((chessboard[srcRow, srcCol].side == defWhite && i != 2) || (chessboard[srcRow, srcCol].side == defBlack && i != 8))
			step(srcRow, srcCol, option, srcRow + moveOption[i].row, srcCol + moveOption[i].col)
		end
	end
end

function defWhiteHorseMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 2 || i == 8 || (chessboard[srcRow, srcCol].side == defWhite && (i == 1 || i == 3)) || (chessboard[srcRow, srcCol].side == defBlack && (i == 7 || i == 9))
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		end
	end
end

function defWhaleMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 2 || i == 8 || (chessboard[srcRow, srcCol].side == defWhite && (i == 7 || i == 9)) || (chessboard[srcRow, srcCol].side == defBlack && (i == 1 || i == 3))
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		end
	end
end

function defLanceMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if (chessboard[srcRow, srcCol].side == defWhite && i == 2) || (chessboard[srcRow, srcCol].side == defBlack && i == 8)
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		end
	end
end

function defReverseChariotMove(srcRow::Int64, srcCol::Int64, option::String)
	for i in 1:9
		if i == 2 || i == 8
			range(srcRow, srcCol, option, srcRow, srcCol, i)
		end
	end
end

function createBoard()
	global chessboard
	grid = [piece("_", defEmpty, defDummy, false, false, false)]
	temp = deepcopy(grid)
	for i in 1:dim - 1
		temp = vcat(temp, deepcopy(grid))
	end
	chessboard = deepcopy(temp)
	for i in 1:dim -1
		chessboard = hcat(chessboard, deepcopy(temp))
	end
end

function add(srcRow::Int64, srcCol::Int64, piecetype::String, colour::String)
	chessboard[srcRow, srcCol].display = "X"
	chessboard[srcRow, srcCol].name = piecetype
	chessboard[srcRow, srcCol].side = colour
end

function delete(srcRow::Int64, srcCol::Int64)
	chessboard[srcRow, srcCol].display = "_"
	chessboard[srcRow,srcCol].name = defEmpty
	chessboard[srcRow,srcCol].side = defDummy
end

function testMove(srcRow::Int64, srcCol::Int64, destRow::Int64, destCol::Int64) # copies move, runs update, modifies global chessboard
	global chessboard
	add(destRow, destCol, chessboard[srcRow, srcCol].name, chessboard[srcRow, srcCol].side)
	delete(srcRow, srcCol)
	moveFunctions("update")
end


function printBoard()
	for i in 1:dim
		for j in 1:dim
			stringTest = chessboard[i,j].display
			print(" $stringTest")
		end
		println("")
	end
end

function printBoardBAttack()
	for i in 1:dim
		for j in 1:dim
			stringTest = chessboard[i,j].BAttack
			print(" $stringTest")
		end
		println("")
	end
end

function printBoardWAttack()
	for i in 1:dim
		for j in 1:dim
			stringTest = chessboard[i,j].WAttack
			print(" $stringTest")
		end
		println("")
	end
end

function prPromote(destRow::Int64, destCol::Int64)
  targetPie = chessboard[destRow,destCol]
  if !targetPie.promote #not promoted
    if dim == tDim && targetPie.name != defFireDemon && targetPie.name != defFreeEagle &&
      targetPie.name != defGreatGeneral && targetPie.name != defKing && targetPie.name != defLionHawk &&
      targetPie.name != defViceGeneral
      if targetPie.side == defWhite
        if destRow <= 5
          chessboard[destRow,destCol].name = chessboard[destRow,destCol].name *" promoted"
          chessboard[destRow,destCol].promote = true
          return true
        end
      elseif targetPie.side == defBlack
        if destRow >= 12
          chessboard[destRow,destCol].name = chessboard[destRow,destCol].name *" promoted"
          chessboard[destRow,destCol].promote = true
          return true
        end
      else
        return false
      end
    elseif dim == cDim && targetPie.name != defKing && targetPie.name != defQueen && targetPie.name != defLion
      if targetPie.side == defWhite
        if destRow <= 4
          chessboard[destRow,destCol].name = chessboard[destRow,destCol].name *" promoted"
          chessboard[destRow,destCol].promote = true
          return true
        end
      elseif targetPie.side == defBlack
        if destRow >= 9
          chessboard[destRow,destCol].name = chessboard[destRow,destCol].name *" promoted"
          chessboard[destRow,destCol].promote = true
          return true
        end
      else
        return false
      end
    elseif dim == sDim && get(prStandard,targetPie.name,"none") != "none"
      if targetPie.side == defWhite
        if destRow <= 3
          chessboard[destRow,destCol].name = chessboard[destRow,destCol].name *" promoted"
          chessboard[destRow,destCol].promote = true
          return true
        end
      elseif targetPie.side == defBlack
        if destRow >= 7
          chessboard[destRow,destCol].name = chessboard[destRow,destCol].name *" promoted"
          chessboard[destRow,destCol].promote = true
          return true
        end
      else
        return false
      end
    elseif dim == mDim && get(prStandard,targetPie.name,"none") != "none"
      if targetPie.side == defWhite
        if destRow <= 1
          chessboard[destRow,destCol].name = chessboard[destRow,destCol].name *" promoted"
          chessboard[destRow,destCol].promote = true
          return true
        end
      elseif targetPie.side == defBlack
        if destRow >= 5
          chessboard[destRow,destCol].name = chessboard[destRow,destCol].name *" promoted"
          chessboard[destRow,destCol].promote = true
          return true
        end
      else
        return false
      end
    end
  end
	return false
end

#

function autoPromote(destRow::Int64, destCol::Int64)  # Run function after pawn, lance or knight move. Check if auto promote.
	if chessboard[destRow, destCol].name == defPawn || chessboard[destRow, destCol].name == defLance
		if chessboard[destRow, destCol].side == defWhite
			if destRow == 1
			  prPromote(destRow, destCol)
				return true
			end
		elseif chessboard[destRow, destCol].side == defBlack
			if destRow == dim
				prPromote(destRow, destCol)
				return true
			end
		else
			return false
		end
	elseif dim != cDim && chessboard[destRow, destCol].name == defKnight
		if chessboard[destRow, destCol].side == defWhite
			if destRow <= 2
				prPromote(destRow, destCol)
				return true
			end
		elseif chessboard[destRow, destCol].side == defBlack
			if destRow >= dim - 1
				prPromote(destRow, destCol)
				return true
			end
		else
			return false
		end
	else
		return false
	end
	return false
end

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