Attribute VB_Name = "Module1"
Global OldComputer, Threat, FirstScore, SecondScore As String
Global FirstInitFile, FirstInitRank, LionAttack, FirstSeeMove, Reload, PawnMate, AA, Suggest, EndMove, Eval, CheckLooked, NoLionCapture, Checked, OriginalPiece, RightClick, OriginalFile, OriginalRank, FirstFile, FirstRank, Influence, CheckTest As Integer
Global CompLionTest, OldNewFile, OldNewRank, ChuLionTest, ProtectLion, XXX, YYY, BlackKingX, BlackKingY, WhiteKingX, WhiteKingY, Changed, FirstTime, MakeMove, CompFile, CompRank, CompMove, LegalMoves, Evaluate, DropTest, OldSeeMove, BestMove As Integer
Global OldThreat, ScoreFormat, PromPiece$, OldChoice, GameName, LionName$, CMove$, Nxt$, Turn, Turn2, Choice As String
Global Computer, SaveTitle$, NewTurn, ExtraPiece, Elapsed$, SpecPower$, Loaded$, Saved$, Datafile, Direct, Cap, Boardbmp, Grade As String
Global Replaying, OldInitRank, OldInitFile, EmperorTest, WhiteEmperor, BlackEmperor, Boardsize, Notate, Graphnum, Pixels, XCorner, SeeFile, SeeRank, PromGraf, Reverse, CapturedPiece As Integer
Global Count As Single
Global Forwards, Tabbing, PieceSizes, ClickPiece, OldLast, OldRank, OldFile, YCorner, Totpiece, PieceNum, J, I, Demon, XStart, LookMate, GameOver As Integer
Global Tilde, Blink, Blocked, MicroCap, BoardSizeX, BoardSizeY, Setup, Reduce, WhiteKing, BlackKing, WhitePrince, BlackPrince, LionPro As Integer
Global ForceProm, AutoPromote, Notice, Backwards, TurnCount, Handicap, Display, NewButton, PromDotY, NewIndex, Rank, File, TotGraph, InitRank, InitFile, Prom As Integer
Global Testing123, Timing, NewGraf, HandGame, Loading, NoPro, GameNo, MoveCount, NewRank, NewFile, Weaker, TeachVer, Teach, CaptPiece As Integer
Global Other, LionTest, NewGame, GeneralInfo, LastWhite, LastBlack, Hook, Range, N, R, F, Area, M, Drop, Dropped, C, D, Capture, RealLion, LionPiece As Integer
Global EndTurn, MovePiece, Selection, WhiteLion, BlackLion, Mate, Taken, P, MoveTest, MoveData, FileInc, RankInc, Last, SeeMove, LionHawkVer As Integer
Global NewX, NewY As Single
Global Board As Form
Global AllBack, Ligui, XA, LastPieceX, LastPieceY, CCC, ShowLast, BlackInfluence, WhiteInfluence, WhiteEmpX, WhiteEmpY, BlackEmpX, BlackEmpY, Level, RealLevel, Depth, TestDepth, FirstLegal As Integer
Global BestTally(26) As Long
Global BestScore, WhiteTally, BlackTally As Long
Global FinalTally(26) As Long
Global TestBoard() As Integer
Global OldHand()  As Integer

Type LegalList
    StartFile As Integer
    StartRank As Integer
    EndFile As Integer
    EndRank As Integer
    StartPiece As Integer
    EndPiece As Integer
End Type
Type MoveRecord
    Caption  As String
    IDStart As Integer
    IDEnd As Integer
    PosStart As Integer
    PosEnd As Integer
End Type
Type CaptiveRecord
    number As Integer
    Positions(1 To 12)  As Integer
    PieceNum(1 To 12) As Integer
End Type
Type Layout
    File As Integer
    Rank As Integer
    Piece As Integer
End Type
Type tEmpty ' SG: Empty is a reserved word in VB 6.0
    File As Integer
    Rank As Integer
End Type
Type Map
    WhiteNum As Integer
    BlackNum As Integer
    WhiteValue As Integer
    BlackValue As Integer
    Info(1 To 512) As Layout
End Type
Type Piece
    number As Integer
    Name As String
    sname As String * 4
    Value As Integer
    PrValue As Integer
    Promotes As Integer
    Graphic As Integer
    PrGraphic As Integer
    Moves(1 To 8)  As Integer
    special As String * 1
    Mask As Integer
    Range As Integer
End Type
Global MoveList(26) As LegalList
Global Clearing() As tEmpty
Global ShortScore() As String
Global BlackDrop(1 To 2) As String
Global WhiteDrop(1 To 2) As String
Global CompLegal() As LegalList
Global ExtraCapture(2000) As Layout
Global ECapture(21) As Layout
Global LionVictim As Layout
Global Pieces() As Piece
Global LowBlack() As Integer
Global LowWhite() As Integer
Global PieceMask() As Integer
Global Squares() As Integer
Global Comp() As Integer
Global CompHeld() As Integer
Global Legal() As Integer
Global OldLegal() As Integer
Global Grafix() As Integer
Global InHand() As Integer
Global TempHand() As Integer
Global CapRef() As Integer
Global AreaOK() As Integer
Global Camps() As Integer
Global Attacker() As Integer
Global OldAttack() As Integer
Global BanMap() As Map
Global BackMap() As Map
Global Score() As MoveRecord
Global Captures() As CaptiveRecord
Global KingTally() As Long
Global OldKingTally(26) As Long

Sub ActingPieces()

If InitFile > 0 Then
    BlackInfluence = 0: WhiteInfluence = 0
    OriginalPiece = Squares(InitFile, InitRank)
    OriginalFile = InitFile: OriginalRank = InitRank
    Influence = 1
    For AB = 1 To BoardSizeY
        For CD = 1 To BoardSizeX
            If Squares(CD, AB) <> 0 Then
                If OriginalPiece <> 0 And Sgn(Squares(CD, AB)) <> Sgn(OriginalPiece) Then
                    Squares(OriginalFile, OriginalRank) = OriginalPiece
                Else
                    If CheckTest <> 1 Then Squares(OriginalFile, OriginalRank) = 0
                End If
                InitFile = CD: InitRank = AB
                If CheckTest <> 1 Or (Sgn(OriginalPiece) <> Sgn(Squares(CD, AB))) Then Validate
            End If
        Next CD
    Next AB
    If CheckTest <> 1 And (Choice = "Maka" Or Choice = "Tai") Then
        If OriginalPiece = 0 Then
            If WhiteEmperor = 1 Then InitFile = WhiteEmpX: InitRank = WhiteEmpY: EmperorInfluence
            If BlackEmperor = 1 Then InitFile = BlackEmpX: InitRank = BlackEmpY: EmperorInfluence
        Else
            If OriginalPiece < 0 And WhiteEmperor = 1 And Pieces(Abs(OriginalPiece)).Name <> "Emperor" Then
                InitFile = WhiteEmpX: InitRank = WhiteEmpY: EmperorInfluence
            End If
            If OriginalPiece > 0 And WhiteEmperor = 1 And BlackEmperor = 0 And BlackInfluence = 0 Then
                InitFile = WhiteEmpX: InitRank = WhiteEmpY: EmperorInfluence
            End If
            If OriginalPiece > 0 And BlackEmperor = 1 And Pieces(Abs(OriginalPiece)).Name <> "Emperor" Then
                InitFile = BlackEmpX: InitRank = BlackEmpY: EmperorInfluence
            End If
            If OriginalPiece < 0 And BlackEmperor = 1 And WhiteEmperor = 0 And WhiteInfluence = 0 Then
                InitFile = BlackEmpX: InitRank = BlackEmpY: EmperorInfluence
            End If

        End If
    End If
    Influence = 0
    Squares(OriginalFile, OriginalRank) = OriginalPiece
End If
End Sub

Sub AddEmperorAttack()

LegalMoves = LegalMoves + 1
If Turn = "White" Then
    CompLegal(LegalMoves).StartFile = WhiteEmpX
    CompLegal(LegalMoves).StartRank = WhiteEmpY
    CompLegal(LegalMoves).EndFile = BlackEmpX
    CompLegal(LegalMoves).EndRank = BlackEmpY
    CompLegal(LegalMoves).StartPiece = Squares(WhiteEmpX, WhiteEmpY)
    CompLegal(LegalMoves).EndPiece = Squares(WhiteEmpX, WhiteEmpY)
Else
    CompLegal(LegalMoves).StartFile = BlackEmpX
    CompLegal(LegalMoves).StartRank = BlackEmpY
    CompLegal(LegalMoves).EndFile = WhiteEmpX
    CompLegal(LegalMoves).EndRank = WhiteEmpY
    CompLegal(LegalMoves).StartPiece = Squares(BlackEmpX, BlackEmpY)
    CompLegal(LegalMoves).EndPiece = Squares(BlackEmpX, BlackEmpY)
End If
End Sub

Sub AddEmperorMove()

LegalMoves = LegalMoves + 1
CompLegal(LegalMoves).StartFile = InitFile
CompLegal(LegalMoves).StartRank = InitRank
CompLegal(LegalMoves).EndFile = SeeFile
CompLegal(LegalMoves).EndRank = SeeRank
CompLegal(LegalMoves).StartPiece = Squares(InitFile, InitRank)
CompLegal(LegalMoves).EndPiece = Squares(InitFile, InitRank)

End Sub

Sub AddHand()

For X = 1 To Capture
    If CapRef(X) = CaptPiece Then
        InHand(X) = InHand(X) + 1
        Board.HandPic(X).Visible = True
        If InHand(X) > 1 Then Board.Held(X).Caption = InHand(X)
        If Choice = "Micro" Then
            MicroCap = X
            MicroAdd
        End If
    Else
        If CapRef(X) = 0 - CaptPiece Then
            InHand(Capture + X) = InHand(Capture + X) + 1
            Board.HandPic(Capture + X).Visible = True
            If InHand(Capture + X) > 1 Then Board.Held(Capture + X).Caption = InHand(Capture + X)
            If Choice = "Micro" Then
                MicroCap = Capture + X
                MicroAdd
            End If
        End If
    End If
Next X

End Sub

Sub AddHand2()
If MovePiece <> 1 Then
    For X = 1 To Capture
        If CapRef(X) = Selection Then
            InHand(X) = InHand(X) + 1
            Board.Held(X).Caption = InHand(X)
            If Choice = "Micro" Then
                MicroCap = X
                MicroAdd
            End If
        Else
            If CapRef(X) = 0 - Selection Then
                InHand(Capture + X) = InHand(Capture + X) + 1
                Board.Held(Capture + X).Caption = InHand(Capture + X)
                If Choice = "Micro" Then
                    MicroCap = Capture + X
                    MicroAdd
                End If
            End If
        End If
    Next X
    CheckAdd
End If
End Sub

Sub AddHand3()
For X = 1 To Capture
    If CapRef(X) = CaptPiece Then
        InHand(X) = InHand(X) + 1
        If Choice = "Micro" Then
            MicroCap = X
            If (MicroCap > 4 And MicroCap < 9) Or MicroCap > 12 Then InHand(MicroCap - 4) = InHand(MicroCap - 4) + 1 Else InHand(MicroCap + 4) = InHand(MicroCap + 4) + 1
        End If
    Else
        If CapRef(X) = 0 - CaptPiece Then
            InHand(Capture + X) = InHand(Capture + X) + 1
            If Choice = "Micro" Then
                MicroCap = Capture + X
                If (MicroCap > 4 And MicroCap < 9) Or MicroCap > 12 Then InHand(MicroCap - 4) = InHand(MicroCap - 4) + 1 Else InHand(MicroCap + 4) = InHand(MicroCap + 4) + 1
            End If
        End If
    End If
Next X

End Sub

Sub AddLegalMove()

LegalMoves = LegalMoves + 1
CompLegal(LegalMoves).StartFile = InitFile
CompLegal(LegalMoves).StartRank = InitRank
CompLegal(LegalMoves).EndFile = SeeFile
CompLegal(LegalMoves).EndRank = SeeRank
If InitFile = 0 Then
    CompLegal(LegalMoves).StartPiece = CapRef(I)
    CompLegal(LegalMoves).EndPiece = CapRef(I)
Else
    CompLegal(LegalMoves).StartPiece = Squares(InitFile, InitRank)
    CompLegal(LegalMoves).EndPiece = Squares(InitFile, InitRank)
    CompPromote
End If
End Sub

Sub AddLionMove()

LegalMoves = LegalMoves + 1
CompLegal(LegalMoves).StartFile = InitFile
CompLegal(LegalMoves).StartRank = InitRank
CompLegal(LegalMoves).EndFile = XXX
CompLegal(LegalMoves).EndRank = YYY
CompLegal(LegalMoves).StartPiece = Squares(NewFile, NewRank)
CompLegal(LegalMoves).EndPiece = Squares(NewFile, NewRank)

End Sub

Sub AddSomePieces()

For K = PieceNum / 2 To 1 Step -1
    A$ = Pieces(K).Name + " " + Pieces(K).sname + Str$(Pieces(K).number)
    If AddPieces.NewPiece.List(AddPieces.NewPiece.ListIndex) = ExtraPiece + " " + Pieces(K).Name + " " + Pieces(K).sname + Space(38 - Len(A$)) + Str$(Pieces(K).number) Then
        Selection = Pieces(K).number
        If ExtraPiece = "White" Then Selection = 0 - Selection
    End If
Next K
AddPieces.Visible = False
Board.Caption = "Adding " + ExtraPiece + " " + Pieces(Abs(Selection)).Name + "s - [Press Right Button When Finished]"
Board.BlackClock.Caption = "00:00:00"
Board.WhiteClock.Caption = "00:00:00"
Board.Timer1.Enabled = False
Board.LastMove.Caption = ""
If Drop = 1 Then
    For X = 1 To Capture
    If ExtraPiece = "Black" Then
        If CapRef(X) = Selection Then
            Board.HandPic(X).Visible = True
            Board.Held(X).Caption = InHand(X)
        End If
    Else
        If CapRef(X) = 0 - Selection Then
            Board.HandPic(Capture + X).Visible = True
            Board.Held(Capture + X).Caption = InHand(Capture + X)
        End If
    End If
    Next X
End If
Unload AddPieces

End Sub

Sub AddTally()
    BestTally(1) = -999999: CompMove = 0: Influence = 3: Evaluate = 1
    WhiteTally = 0: BlackTally = 0
    MakeMap
    For DD = 1 To BoardSizeY
        For EE = 1 To BoardSizeX
            If Squares(EE, DD) < 0 Then WhiteTally = WhiteTally + (Pieces(Abs(Squares(EE, DD))).Value * 10)
            If Squares(EE, DD) > 0 Then BlackTally = BlackTally + (Pieces(Abs(Squares(EE, DD))).Value * 10)
            If BanMap(EE, DD).BlackNum = 0 And BanMap(EE, DD).WhiteNum > 0 Then
                WhiteTally = 1 + Abs((BoardSizeY / 2) - DD) + WhiteTally
                If Squares(EE, DD) > 0 And Turn = "Black" Then BlackTally = BlackTally - (Pieces(Abs(Squares(EE, DD))).Value * 10)
            End If
            If BanMap(EE, DD).WhiteNum = 0 And BanMap(EE, DD).BlackNum > 0 Then
                BlackTally = Abs((BoardSizeY / 2) - DD) + BlackTally
                If Squares(EE, DD) < 0 And Turn = "White" Then WhiteTally = WhiteTally - (Pieces(Abs(Squares(EE, DD))).Value * 10)
            End If
            If BanMap(EE, DD).WhiteNum > 0 And BanMap(EE, DD).BlackNum > 0 Then
                If Squares(EE, DD) > 0 And Turn = "Black" Then
                    For QQ = 1 To Attacker(EE, DD)
                        If BanMap(EE, DD).Info(QQ).Piece < 0 And (Pieces(Abs(BanMap(EE, DD).Info(QQ).Piece)).Value < LowWhite(EE, DD) Or LowWhite(EE, DD) = 0) Then LowWhite(EE, DD) = Pieces(Abs(BanMap(EE, DD).Info(QQ).Piece)).Value
                    Next QQ
                    BlackLoss = ((Pieces(Abs(Squares(EE, DD))).Value - LowWhite(EE, DD)) * 10)
                    If BlackLoss > HighBlackLoss Then HighBlackLoss = BlackLoss
                End If
                If Squares(EE, DD) < 0 And Turn = "White" Then
                    For QQ = 1 To Attacker(EE, DD)
                        If BanMap(EE, DD).Info(QQ).Piece > 0 And (Pieces(Abs(BanMap(EE, DD).Info(QQ).Piece)).Value < LowBlack(EE, DD) Or LowBlack(EE, DD) = 0) Then LowBlack(EE, DD) = Pieces(Abs(BanMap(EE, DD).Info(QQ).Piece)).Value
                    Next QQ
                    WhiteLoss = ((Pieces(Abs(Squares(EE, DD))).Value - LowBlack(EE, DD)) * 10)
                    If WhiteLoss > HighWhiteLoss Then HighWhiteLoss = WhiteLoss
                End If
            End If
            LowWhite(EE, DD) = 0: LowBlack(EE, DD) = 0
         Next EE
    Next DD
    If Drop = 1 Then
        For FF = 1 To Capture
            BlackTally = BlackTally + (Pieces(Abs(CapRef(FF))).Value * 11) * (InHand(FF))
            WhiteTally = WhiteTally + (Pieces(Abs(CapRef(FF + Capture))).Value * 11) * (InHand(FF + Capture))
        Next FF
    End If
    BlackTally = BlackTally - HighBlackLoss: HighBlackLoss = 0
    WhiteTally = WhiteTally - HighWhiteLoss: HighWhiteLoss = 0
    If Turn = "White" Then BestTally(1) = WhiteTally - BlackTally Else BestTally(1) = BlackTally - WhiteTally
End Sub

Sub AreaMove()
AreaMove2
For X = 1 To Area - 1
    For N = InitRank - X To InitRank + X
        If N > 0 And N <= BoardSizeY Then
            For P = InitFile - X To InitFile + X
                If P > 0 And P <= BoardSizeX Then
                    If AreaOK(P, N) = 1 And (Abs(P - InitFile) <= X And Abs(N - InitRank) <= X) Then AreaMove2
                End If
            Next P
        End If
    Next N
Next X
End Sub

Sub AreaMove2()
Evaluate = 0
For Q = N - 1 To N + 1
    If Q > 0 And Q <= BoardSizeY Then
        For S = P - 1 To P + 1
            If S > 0 And S <= BoardSizeX Then
                If Squares(S, Q) = 0 Then
                    Board.FillColor = &HFFFFFF
                    If SeeMove = 1 Then SeeFile = S: SeeRank = Q: LookMove
                    Legal(S, Q) = 1
                    AreaOK(S, Q) = 1
                    NewFile = S: NewRank = Q: CheckBurn
                    If Demon = 1 Then FireDemon
                Else
                    If Sgn(Squares(S, Q)) <> Sgn(Squares(InitFile, InitRank)) Or ((Influence > 0) And (S <> InitFile Or Q <> InitRank)) Then
                        Board.FillColor = &HFF&
                        If SeeMove = 1 Then SeeFile = S: SeeRank = Q: LookMove
                        Legal(S, Q) = 1
                        NewFile = S: NewRank = Q: CheckBurn
                        If Demon = 1 Then FireDemon
                    End If
                End If
            End If
        Next S
    End If
Next Q
End Sub

Sub AskMate()

If (Pieces(Abs(CapRef(I))).Name = "Pawn" Or Pieces(Abs(CapRef(I))).Name = "Sparrow Pawn" Or Pieces(Abs(CapRef(I))).Name = "Swallow" Or Pieces(Abs(CapRef(I))).Name = "Dolphin") And (Choice <> "Micro" And Choice <> "Yari") Then
    CheckDrop = 0
    If Turn = "Black" And WhiteKingY < BoardSizeY Then
        If Legal(WhiteKingX, WhiteKingY + 1) = 1 Then Squares(WhiteKingX, WhiteKingY + 1) = CapRef(I): File = WhiteKingX: Rank = WhiteKingY + 1: CheckDrop = 1
    End If
    If Turn = "White" And BlackKingY > 1 Then
        If Legal(BlackKingX, BlackKingY - 1) = 1 Then Squares(BlackKingX, BlackKingY - 1) = CapRef(I): File = BlackKingX: Rank = BlackKingY - 1: CheckDrop = 1
    End If
    If CheckDrop = 1 Then
        For CC = 1 To BoardSizeY
            For BB = 1 To BoardSizeX
                Comp(BB, CC) = Squares(BB, CC)
                OldLegal(BB, CC) = Legal(BB, CC)
            Next BB
        Next CC
        OldInfluence = Influence: OldEvaluate = Evaluate: OldCompMove = CompMove
        OldSeeMove = SeeMove: Influence = 3: Evaluate = 1: CompMove = 0: SeeMove = 1
        TestFile = File: TestRank = Rank
        MakeMap
        File = TestFile: Rank = TestRank
        For CC = 1 To BoardSizeY
            For BB = 1 To BoardSizeX
                Squares(BB, CC) = Comp(BB, CC)
            Next BB
        Next CC
        Influence = OldInfluence: Evaluate = OldEvaluate: CompMove = OldCompMove
        If Turn = "Black" Then
            If BanMap(File, Rank).WhiteNum < 2 And BanMap(File, Rank).BlackNum > 0 Then
                PawnMate = 1
                For SS = Rank - 2 To Rank
                    For TT = File - 1 To File + 1
                        If TT > 0 And TT <= BoardSizeX And SS > 0 And SS <= BoardSizeY And (SS <> Rank Or TT <> File) And (SS <> WhiteKingX Or TT <> WhiteKingY) Then
                            If BanMap(TT, SS).BlackNum = 0 And Squares(TT, SS) >= 0 Then PawnMate = 0
                        End If
                    Next TT
                Next SS
                If PawnMate = 1 Then OldLegal(File, Rank) = 0
            End If
        Else
            If BanMap(File, Rank).BlackNum < 2 And BanMap(File, Rank).WhiteNum > 0 Then
                PawnMate = 1
                For SS = Rank To Rank + 2
                    For TT = File - 1 To File + 1
                        If TT > 0 And TT <= BoardSizeX And SS > 0 And SS <= BoardSizeY And (SS <> Rank Or TT <> File) And (SS <> BlackKingY Or TT <> BlackKingX) Then
                            If BanMap(TT, SS).WhiteNum = 0 And Squares(TT, SS) <= 0 Then PawnMate = 0
                        End If
                    Next TT
                Next SS
                If PawnMate = 1 Then OldLegal(File, Rank) = 0
            End If
        End If
        SeeMove = OldSeeMove
        For AA = 1 To BoardSizeY
            For BB = 1 To BoardSizeX
                Squares(BB, AA) = Comp(BB, AA)
                Legal(BB, AA) = OldLegal(BB, AA)
            Next BB
        Next AA
        Squares(File, Rank) = 0
    End If
End If
PawnMate = 0
End Sub

Sub AutoMessage()

Board.PieceID.ForeColor = &H8000&
Board.PieceID.Caption = PromPiece$ + " promotes"
If Game <> "Micro" And Game <> "Tori" And Game <> "Whale" And Game <> "Maka" And Game <> "DaiDai" And Game <> "Tai" And Computer <> Turn And Computer <> "Both" Then
    Notice = 1
    Board.Caption = "Double Click on new " + Pieces(Abs(Squares(File, Rank))).Name + " if not promoting."
End If
End Sub

Sub BugFix()

Count = 0: Backwards = 0: BugNo = 64
Select Case Choice
    Case "HShogi": BugNo = 40
    Case "Wa": BugNo = 69
    Case "Chu": BugNo = 93
    Case "Dai": BugNo = 132
    Case "Tenjiku": BugNo = 158
    Case "DaiDai": BugNo = 192
    Case "Maka": BugNo = 192
    Case "Tai": BugNo = 356
    Case "Heian": BugNo = 92
End Select
For A = 0 To BugNo
    If Board.showpic(A).Visible = False Then Count = Count + 1
Next A
For A = 0 To BugNo
    Board.showpic(A).Visible = False
    For B = 1 To BoardSizeY
        For C = 1 To BoardSizeX
            If Grafix(C, B) = A Then Board.showpic(A).Visible = True
        Next C
    Next B
Next A
Setup = 0

End Sub

Sub ChangeGame()
Unload Start
Unload Board
Unload PieceHelp
Unload RulesHelp
Main
End Sub

Sub ChangeSides()
If Pieces(Abs(Squares(File, Rank))).Name = "Porpoise" Then
    Board.Caption = "Captured Porpoise becomes a Killer Whale"
    Notice = 1
End If
If Pieces(Abs(Squares(File, Rank))).Promotes = 0 And Pieces(Abs(Squares(File, Rank))).PrGraphic > 0 Then
    CaptPiece = Pieces(Abs(Squares(File, Rank))).PrGraphic
    If Squares(File, Rank) > 0 Then
        CaptPiece = 0 - CaptPiece
    End If
Else
    CaptPiece = 0 - Squares(File, Rank)
End If
AddHand
End Sub

Sub ChangeTurn()
    
If NewTurn = "Black" Then
    Board.LastMove.Caption = ""
    MoveCount = 0: TurnCount = 0
    Board.NextMove.Caption = "Black to Move"
    Turn = "Black"
    Board.BlackClock.Caption = "00:00:00"
    Board.WhiteClock.Caption = "00:00:00"
End If
If NewTurn = "White" Then
    Board.LastMove.Caption = ""
    MoveCount = 1: TurnCount = 0
    Turn = "White"
    Board.NextMove.Caption = "White to Move"
    Board.BlackClock.Caption = "00:00:00"
    Board.WhiteClock.Caption = "00:00:00"
End If
End Sub

Sub CheckAdd()
Board.LastMove.Caption = ""
Count = 0: Setup = 1
For K = 1 To BoardSizeY
    For L = 1 To BoardSizeX
        If Squares(L, K) <> 0 Then Count = Count + 1
    Next L
Next K
If Drop = 1 Then
    For K = 1 To Capture * 2
        Count = Count + InHand(K)
        If Choice = "Micro" Then Count = Count - (InHand(K) / 2)
    Next K
End If
If Count >= Totpiece Then
    Board.Caption = "You can not add any more pieces!"
    Notice = 1
    Selection = 0: MovePiece = 0
    Board.Timer1.Enabled = True
    TurnCount = 0: MoveCount = 0
    If Drop = 1 Then ResetHand
    If Turn = "White" Then MoveCount = 1
    BugFix
Else
    If Selection = 0 Then Load AddPieces
End If
End Sub

Sub CheckBurn()
Evaluate = 0
For K = NewRank - 1 To NewRank + 1
    For L = NewFile - 1 To NewFile + 1
        If L > 0 And L <= BoardSizeX And K > 0 And K <= BoardSizeY Then
            If (K <> NewRank Or L <> NewFile) And Squares(L, K) <> 0 Then
                If Pieces(Abs(Squares(L, K))).special = "F" And Sgn(Squares(InitFile, InitRank)) <> Sgn(Squares(L, K)) Then
                    Board.FillColor = &H0&
                    If SeeMove = 1 Then SeeFile = NewFile: SeeRank = NewRank: LookMove
                    Legal(NewFile, NewRank) = 3
                End If
            End If
        End If
    Next L
Next K
End Sub

Sub CheckEmperor()
OldInfluence = Influence: ProtectLion = 0: OldSeeMove = SeeMove: SeeMove = 1
Influence = 1: ChuLionTest = 1: OldInitFile = InitFile: OldInitRank = InitRank
OldNewFile = NewFile: OldNewRank = NewRank: OldSeeFile = SeeFile: OldSeeRank = SeeRank: OldFile = File: OldRank = Rank
For FFF = 1 To BoardSizeY
    For GGG = 1 To BoardSizeX
        OldLegal(GGG, FFF) = Legal(GGG, FFF)
    Next GGG
Next FFF
For FFF = 1 To BoardSizeY
    For GGG = 1 To BoardSizeX
        If Sgn(Squares(GGG, FFF)) = Sgn(Squares(OldNewFile, OldNewRank)) Then
            InitFile = GGG: InitRank = FFF: Validate
            If ProtectLion = 1 Then OldLegal(OldNewFile, OldNewRank) = 0: Exit For
        End If
    Next GGG
If ProtectLion = 1 Then Exit For
Next FFF
For FFF = 1 To BoardSizeY
    For GGG = 1 To BoardSizeX
        Legal(GGG, FFF) = OldLegal(GGG, FFF)
    Next GGG
Next FFF
Influence = OldInfluence
ChuLionTest = 0: InitFile = OldInitFile: InitRank = OldInitRank
NewFile = OldNewFile: NewRank = OldNewRank: SeeFile = OldSeeFile: SeeRank = OldSeeRank: File = OldFile: Rank = OldRank
SeeMove = OldSeeMove
End Sub

Sub CheckMate()

If Turn = "White" Then
    If Abs(Squares(File, Rank)) = 1 Or Pieces(Abs(Squares(File, Rank))).Name = "Emperor" Then BlackKing = 1
    If Pieces(Abs(Squares(File, Rank))).Name = "Crown Prince" Or Pieces(Abs(Squares(File, Rank))).Name = "Prince" Then BlackPrince = BlackPrince - 1
    If Pieces(Abs(Squares(File, Rank))).Name = "Emperor" Then BlackEmperor = 0
Else
    If Turn = "Black" Then
        If Abs(Squares(File, Rank)) = 1 Or Pieces(Abs(Squares(File, Rank))).Name = "Emperor" Then WhiteKing = 1
        If Pieces(Abs(Squares(File, Rank))).Name = "Emperor" Then WhiteEmperor = 0
        If Pieces(Abs(Squares(File, Rank))).Name = "Crown Prince" Or Pieces(Abs(Squares(File, Rank))).Name = "Prince" Then WhitePrince = WhitePrince - 1
    End If
End If
If Choice = "Tenjiku" Or Choice = "Maka" Or Choice = "Tai" Then
    If BlackKing = 1 And BlackPrince = 0 Then Mate = 1: GameOver = 1
    If WhiteKing = 1 And WhitePrince = 0 Then Mate = 1: GameOver = 1
End If
End Sub

Sub ChuLion()

OldInfluence = Influence: ProtectLion = 0: OldSeeMove = SeeMove: SeeMove = 1
Influence = 1: ChuLionTest = 1: OldInitFile = InitFile: OldInitRank = InitRank
OldNewFile = NewFile: OldNewRank = NewRank: OldSeeFile = SeeFile: OldSeeRank = SeeRank: OldFile = File: OldRank = Rank
For FFF = 1 To BoardSizeY
    For GGG = 1 To BoardSizeX
        OldLegal(GGG, FFF) = Legal(GGG, FFF)
    Next GGG
Next FFF
For FFF = 1 To BoardSizeY
    For GGG = 1 To BoardSizeX
        If Sgn(Squares(GGG, FFF)) = Sgn(Squares(OldNewFile, OldNewRank)) Then
            InitFile = GGG: InitRank = FFF: Validate
            If ProtectLion = 1 Then OldLegal(OldNewFile, OldNewRank) = 0: Exit For
        End If
    Next GGG
If ProtectLion = 1 Then Exit For
Next FFF
For FFF = 1 To BoardSizeY
    For GGG = 1 To BoardSizeX
        Legal(GGG, FFF) = OldLegal(GGG, FFF)
    Next GGG
Next FFF
Influence = OldInfluence
ChuLionTest = 0: InitFile = OldInitFile: InitRank = OldInitRank: SeeMove = OldSeeMove
NewFile = OldNewFile: NewRank = OldNewRank: SeeFile = OldSeeFile: SeeRank = OldSeeRank: File = OldFile: Rank = OldRank

End Sub

Sub ClearBoard()
Response% = MsgBox("Are You Sure ?", 36, "Clear the Board")
If Response% = 6 Then
    For A = 1 To BoardSizeY
        For B = 1 To BoardSizeX
            If Squares(B, A) <> 0 Then
                Board.showpic(Grafix(B, A)).Visible = False
                Board.showpic(Grafix(B, A)).Move 0, 0
                Squares(B, A) = 0
            End If
            Grafix(B, A) = -1
        Next B
    Next A
    If Drop = 1 Then
        For A = 1 To Capture * 2
            InHand(A) = 0
            Board.HandPic(A).Visible = False
            Board.Held(A).Caption = ""
        Next A
    End If
    WhitePrince = 0: BlackPrince = 0
    Board.LastMove.Caption = ""
    MoveCount = 0: TurnCount = 0
    Board.BlackClock.Caption = "00:00:00"
    Board.WhiteClock.Caption = "00:00:00"
    Board.Timer1.Enabled = False
End If
End Sub

Sub ClearInfo()

If CapturedPiece <> 1 Then
    Changed = Changed + 1
    Clearing(Changed).File = File
    Clearing(Changed).Rank = Rank
End If
CapturedPiece = 0
For JJ = 1 To BoardSizeY
    For KK = 1 To BoardSizeX
        For MM = 1 To Attacker(KK, JJ)
            If BanMap(KK, JJ).Info(MM).File = File And BanMap(KK, JJ).Info(MM).Rank = Rank Then
                If Attacker(KK, JJ) = 1 Then
                    BanMap(KK, JJ).Info(MM).File = 0
                    BanMap(KK, JJ).Info(MM).Rank = 0
                    BanMap(KK, JJ).Info(MM).Piece = 0
                Else
                For NN = MM To Attacker(KK, JJ) - 1
                    BanMap(KK, JJ).Info(NN).File = BanMap(KK, JJ).Info(NN + 1).File
                    BanMap(KK, JJ).Info(NN).Rank = BanMap(KK, JJ).Info(NN + 1).Rank
                    BanMap(KK, JJ).Info(NN).Piece = BanMap(KK, JJ).Info(NN + 1).Piece
                Next NN
                End If
                Attacker(KK, JJ) = Attacker(KK, JJ) - 1
                If Squares(File, Rank) < 0 Then
                    BanMap(KK, JJ).WhiteNum = BanMap(KK, JJ).WhiteNum - 1
                Else
                    If Squares(File, Rank) > 0 Then
                        BanMap(KK, JJ).BlackNum = BanMap(KK, JJ).BlackNum - 1
                    End If
                End If
            End If
        Next MM
    Next KK
Next JJ

End Sub

Sub ClearLegal()

If Notice = 0 And Checked <> 1 Then Board.PieceID.Caption = ""
If GameOver = 1 Then
    Board.NextMove.Caption = "Game Over"
Else
    If Turn = "White" Then Board.NextMove.Caption = "White to Move" Else Board.NextMove.Caption = "Black to Move"
End If
If SeeMove = 1 Then Board.Refresh
For A = 1 To BoardSizeY
   For B = 1 To BoardSizeX
       Legal(B, A) = 0
       AreaOK(B, A) = 0
   Next B
Next A
End Sub

Sub Clock()
If Timing = 0 And GameOver <> 1 Then
    If (Turn = "White" And Level > 0) Or (Turn = "Black" And Level = 0) Then
        Elapsed$ = Board.WhiteClock.Caption
        SetClock
        Board.WhiteClock.Caption = Elapsed$
    Else
        Elapsed$ = Board.BlackClock.Caption
        SetClock
        Board.BlackClock.Caption = Elapsed$
    End If
End If
End Sub

Sub ClocksOff()

Board.Timer1.Enabled = False
Board.WhiteClock.Caption = "00:00:00"
Board.BlackClock.Caption = "00:00:00"
Timing = 1
Board.WhiteClock.Visible = False
Board.BlackClock.Visible = False
Board.MnuClockOff.Enabled = False
Board.MnuClockOn.Enabled = True
Board.MnuClockOff.Checked = True
Board.MnuClockOn.Checked = False

End Sub

Sub ClocksOn()

Board.Timer1.Enabled = True
Board.WhiteClock.Caption = "00:00:00"
Board.BlackClock.Caption = "00:00:00"
Timing = 0
Board.WhiteClock.Visible = True
Board.BlackClock.Visible = True
Board.MnuClockOff.Enabled = True
Board.MnuClockOn.Enabled = False
Board.MnuClockOn.Checked = True
Board.MnuClockOff.Checked = False

End Sub

Sub CompLion()

CompLionTest = 1
AddLegalMove
DeadPiece = Squares(NewFile, NewRank)
Squares(NewFile, NewRank) = Squares(InitFile, InitRank)
Squares(InitFile, InitRank) = 0
For YYY = NewRank - 1 To NewRank + 1
    For XXX = NewFile - 1 To NewFile + 1
        If XXX > 0 And XXX <= BoardSizeX And YYY > 0 And YYY <= BoardSizeY Then
            If Squares(XXX, YYY) = 0 Or Sgn(Squares(XXX, YYY)) <> Sgn(Squares(NewFile, NewRank)) Then
                AddLionMove
                ExtraCapture(LegalMoves).Piece = DeadPiece
                ExtraCapture(LegalMoves).File = NewFile
                ExtraCapture(LegalMoves).Rank = NewRank
            End If
        End If
    Next XXX
Next YYY
Squares(InitFile, InitRank) = Squares(NewFile, NewRank)
Squares(NewFile, NewRank) = DeadPiece

End Sub

Sub CompLionPower()

CompLionTest = 1
AddLegalMove
DeadPiece = Squares(NewFile, NewRank)
Squares(NewFile, NewRank) = Squares(InitFile, InitRank)
Squares(InitFile, InitRank) = 0
For WWW = -1 To 1 Step 2
    XXX = NewFile + (FileInc * WWW)
    YYY = NewRank + (RankInc * WWW)
    If XXX > 0 And XXX <= BoardSizeX And YYY > 0 And YYY <= BoardSizeY Then
        If Squares(XXX, YYY) = 0 Or Sgn(Squares(XXX, YYY)) <> Sgn(Squares(NewFile, NewRank)) Then
            AddLionMove
            ExtraCapture(LegalMoves).Piece = DeadPiece
            ExtraCapture(LegalMoves).File = NewFile
            ExtraCapture(LegalMoves).Rank = NewRank
        End If
    End If
Next WWW
Squares(InitFile, InitRank) = Squares(NewFile, NewRank)
Squares(NewFile, NewRank) = DeadPiece

End Sub

Sub CompMain()

If Level <> 0 And (Computer = "White" Or Computer = "Black") Then Board.MnuSwitch.Enabled = True Else Board.MnuSwitch.Enabled = False

' Find Legal Moves

If GameOver = 1 Then Exit Sub
For AA = 1 To BoardSizeY
    For BB = 1 To BoardSizeX
        Comp(BB, AA) = Squares(BB, AA)
    Next BB
Next AA
CompMove = 1: LegalMoves = 0
For YZ = 1 To BoardSizeY
    For VX = 1 To BoardSizeX
        If Turn = "White" Then
            If Squares(VX, YZ) < 0 Then
                InitFile = VX: InitRank = YZ
                I = Grafix(VX, YZ)
                Validate
                Taken = 0
            End If
        Else
            If Squares(VX, YZ) > 0 Then
                InitFile = VX: InitRank = YZ
                I = Grafix(VX, YZ)
                Validate
                Taken = 0
            End If
        End If
    Next VX
DoEvents
Next YZ

' Find Legal Drops

If Drop = 1 Then
    If (Turn = "Black" And Reverse = 0) Or (Turn = "White" And Reverse = 1) Then
        For TU = 1 To Capture
            ResetLegal
            If InHand(TU) > 0 Then
                I = TU: InitFile = 0: InitRank = 0
                HeldValid
                DoEvents
            End If
        Next TU
    Else
        For TU = Capture + 1 To Capture * 2
            If InHand(TU) > 0 Then
                ResetLegal
                I = TU: InitFile = 0: InitRank = 0
                HeldValid
                DoEvents
            End If
        Next TU
    End If
End If

' Find Legal Emperor Moves

If Choice = "Tai" Or Choice = "Maka" Then
    OldInfluence = Influence: CompMove = 0
    If WhiteEmperor = 1 And BlackEmperor = 1 Then AddEmperorAttack
    If (Turn = "White" And WhiteEmperor = 1) Or (Turn = "Black" And BlackEmperor = 1) Then
        Influence = 2
        For AB = 1 To BoardSizeY
            For CD = 1 To BoardSizeX
                InitFile = CD: InitRank = AB: Validate
            Next CD
        Next AB
        FindEmperorMove
    End If
Influence = OldInfluence: CompMove = 1
End If

FirstLegal = LegalMoves
If FirstLegal < Level Then TestDepth = FirstLegal Else TestDepth = Level
If LookMate = 1 Then ConsiderMate Else ConsiderMove
Evaluate = 0: CompMove = 0: Influence = 0: EndMove = 0
If Suggest = 1 Then SuggestMove: Exit Sub
If GameOver = 1 Then Exit Sub
If Level > 1 Then LookAhead
    
' Make Best Move

For AA = 1 To BoardSizeY
    For BB = 1 To BoardSizeX
        Squares(BB, AA) = Comp(BB, AA)
    Next BB
Next AA
For A = 1 To BoardSizeY
    For B = 1 To BoardSizeX
        Legal(B, A) = 0
        AreaOK(B, A) = 0
    Next B
Next A
OldSeeMove = SeeMove: SeeMove = 0
If LookMate = 1 Then Exit Sub
If CompLegal(BestMove).StartFile = 0 Then
    InitFile = 0
    DropTest = 1
    TestDrop
Else
    InitRank = CompLegal(BestMove).StartRank
    InitFile = CompLegal(BestMove).StartFile
    I = Grafix(InitFile, InitRank)
    If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Emperor" Then Legal(CompLegal(BestMove).EndFile, CompLegal(BestMove).EndRank) = 1
    Validate
End If
SeeMove = OldSeeMove: CompMove = 1: Evaluate = 0: MakeMove = 1
File = CompLegal(BestMove).EndFile
Rank = CompLegal(BestMove).EndRank
If InitFile = 0 Then
    MakeDrop
    DropTest = 0
Else
    If Pieces(Abs(Squares(InitFile, InitRank))).special = "L" Or Pieces(Abs(Squares(InitFile, InitRank))).Name = "Horned Falcon" Or Pieces(Abs(Squares(InitFile, InitRank))).Name = "Soaring Eagle" Then Legal(InitFile, InitRank) = 1
    I = Grafix(InitFile, InitRank)
    If Squares(File, Rank) = 0 Then
        FormDrop
    Else
        NewIndex = Grafix(File, Rank)
        PicDrop
    End If
End If
If Taken = 1 And (Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tai") Then
    I = Grafix(File, Rank)
    Promote
Else
If CompLegal(BestMove).StartPiece <> CompLegal(BestMove).EndPiece And Squares(File, Rank) <> 0 Then
    I = Grafix(File, Rank)
    Promote
End If
End If
CompMove = 0: Evaluate = 0: LegalMoves = 0
If Mate <> 1 Then NextTurn2

End Sub

Sub CompMate()

If Squares(File, Rank) = 1 And Turn = "White" Then
    If (Abs(File - CompLegal(AA).EndFile) < 2 And Abs(Rank - CompLegal(AA).EndRank) < 2) And BanMap(CompLegal(AA).EndFile, CompLegal(AA).EndRank).BlackNum < 2 And BanMap(CompLegal(AA).EndFile, CompLegal(AA).EndRank).WhiteNum > 0 And BanMap(File, Rank).WhiteNum > 0 And CompLegal(AA).EndPiece <> -1 Then
        MateCheck = 1
        For SS = Rank - 1 To Rank + 1
            For TT = File - 1 To File + 1
                If TT > 0 And TT <= BoardSizeX And SS > 0 And SS <= BoardSizeY And (SS <> Rank Or TT <> File) Then
                    If BanMap(TT, SS).WhiteNum = 0 And Squares(TT, SS) <= 0 Then MateCheck = 0
                End If
            Next TT
        Next SS
        If MateCheck = 1 Then WhiteTally = WhiteTally + 8888 Else WhiteTally = WhiteTally + 20
    Else
        If BanMap(File, Rank).WhiteNum > 0 And BanMap(CompLegal(AA).EndFile, CompLegal(AA).EndRank).BlackNum = 0 And CompLegal(AA).EndPiece <> -1 Then WhiteTally = WhiteTally + 20
    End If
End If
If Squares(File, Rank) = -1 And Turn = "Black" Then
    If Abs(File - CompLegal(AA).EndFile) < 2 And Abs(Rank - CompLegal(AA).EndRank) < 2 And BanMap(CompLegal(AA).EndFile, CompLegal(AA).EndRank).WhiteNum < 2 And BanMap(CompLegal(AA).EndFile, CompLegal(AA).EndRank).BlackNum > 0 And BanMap(File, Rank).BlackNum > 0 And CompLegal(AA).EndPiece <> 1 Then
        MateCheck = 1
        For SS = Rank - 1 To Rank + 1
            For TT = File - 1 To File + 1
                If TT > 0 And TT <= BoardSizeX And SS > 0 And SS <= BoardSizeY And (SS <> Rank Or TT <> File) Then
                    If BanMap(TT, SS).BlackNum = 0 And Squares(TT, SS) >= 0 Then MateCheck = 0
                End If
            Next TT
        Next SS
        If MateCheck = 1 Then BlackTally = BlackTally + 8888 Else BlackTally = BlackTally + 20
    Else
        If BanMap(File, Rank).BlackNum > 0 And BanMap(CompLegal(AA).EndFile, CompLegal(AA).EndRank).WhiteNum = 0 And CompLegal(AA).EndPiece <> 1 Then BlackTally = BlackTally + 20
    End If
End If
            

End Sub

Sub CompPromote()

ForceProm = 0: Taken = 0
If Choice = "Micro" Or Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tai" Then
    If Squares(SeeFile, SeeRank) <> 0 Then
        If Sgn(Squares(InitFile, InitRank)) <> Sgn(Squares(SeeFile, SeeRank)) Then
            Taken = 1: ForceProm = 1
            CompPromote2
        End If
    End If
Else
    If Pieces(Abs(Squares(InitFile, InitRank))).special = "1" Then
        If Squares(InitFile, InitRank) > 0 And SeeRank = 1 Then ForceProm = 1: CompPromote2
        If Squares(InitFile, InitRank) < 0 And SeeRank = BoardSizeY Then ForceProm = 1: CompPromote2
    End If
    If Pieces(Abs(Squares(InitFile, InitRank))).special = "2" Then
        If Squares(InitFile, InitRank) > 0 And SeeRank < 3 Then ForceProm = 1: CompPromote2
        If Squares(InitFile, InitRank) < 0 And SeeRank > BoardSizeY - 2 Then ForceProm = 1: CompPromote2
    End If
    If Squares(InitFile, InitRank) > 0 And (SeeRank <= PromDotY Or InitRank <= PromDotY) Then CompPromote2
    If Squares(InitFile, InitRank) < 0 And (SeeRank > BoardSizeY - PromDotY Or InitRank > BoardSizeY - PromDotY) Then CompPromote2
End If
End Sub

Sub CompPromote2()

If (Choice <> "Micro" And Choice <> "Tai" And Choice <> "Maka" And Choice <> "DaiDai") Or (Taken = 1) Then
    If (ForceProm = 1 And Pieces(Abs(Squares(InitFile, InitRank))).Promotes <> 0) Or Prom = 1 Then
        CompLegal(LegalMoves).EndPiece = Pieces(Abs(Squares(InitFile, InitRank))).Promotes
        If CompLegal(LegalMoves).StartPiece < 0 Then CompLegal(LegalMoves).EndPiece = 0 - CompLegal(LegalMoves).EndPiece
    Else
        If (Pieces(Abs(Squares(InitFile, InitRank))).Promotes <> 0) Then
            LegalMoves = LegalMoves + 1
            CompLegal(LegalMoves).StartFile = InitFile
            CompLegal(LegalMoves).StartRank = InitRank
            CompLegal(LegalMoves).EndFile = SeeFile
            CompLegal(LegalMoves).EndRank = SeeRank
            CompLegal(LegalMoves).StartPiece = Squares(InitFile, InitRank)
            CompLegal(LegalMoves).EndPiece = Pieces(Abs(Squares(InitFile, InitRank))).Promotes
            If Squares(InitFile, InitRank) < 0 Then CompLegal(LegalMoves).EndPiece = 0 - CompLegal(LegalMoves).EndPiece
        End If
    End If
End If
End Sub

Sub CompTeach()

Board.MnuVer2.Enabled = False
Board.MnuVer1.Enabled = False
Board.MnuVer1.Checked = True
Board.MnuVer2.Checked = False
TeachVer = 1
If Choice = "Tai" Then
    Pieces(29).PrValue = 28: Pieces(100).Value = 28
Else
    Pieces(29).PrValue = 28: Pieces(76).Value = 28
End If
End Sub

Sub CompTurn()

If LegalMoves = 0 Then
    Board.Caption = Cap
    If Computer = Turn Then
        FirstSeeMove = SeeMove
        SeeMove = 1
        CompMain
    End If
End If
End Sub

Sub CompVComp()
Do
CompMain
Loop Until GameOver = 1 Or Mate = 1
If GameOver = 1 Then NextTurn2
GameOver = 0
End Sub

Sub ConfigLoad()

If Loading <> 1 Then
    Open Direct + "/" + "Shogi.cfg" For Input As #4
    Input #4, SeeMove, Timing, Computer, Threat, AutoPromote, Notate, LionHawkVer, TeachVer, Eval, Grade, ShowLast
    Close #4
End If
If SeeMove = 1 Then
    Board.MnuShowOn.Enabled = False
    Board.MnuShowOn.Checked = True
    Board.MnuShowOff.Enabled = True
    Board.MnuShowOff.Checked = False
Else
    Board.MnuShowOn.Enabled = True
    Board.MnuShowOn.Checked = False
    Board.MnuShowOff.Enabled = False
    Board.MnuShowOff.Checked = True
End If
ConfigLoad2
If ShowLast = 1 Then
    Board.MnuShowLastOn.Enabled = False
    Board.MnuShowLastOn.Checked = True
    Board.MnuShowLastOff.Enabled = True
    Board.MnuShowLastOff.Checked = False
Else
    Board.MnuShowLastOn.Enabled = True
    Board.MnuShowLastOn.Checked = False
    Board.MnuShowLastOff.Enabled = False
    Board.MnuShowLastOff.Checked = True
End If
If Threat = "On" Then
    Board.MnuThreatOn.Enabled = False
    Board.MnuThreatOn.Checked = True
    Board.MnuThreatOff.Enabled = True
    Board.MnuThreatOff.Checked = False
Else
    Board.MnuThreatOn.Enabled = True
    Board.MnuThreatOn.Checked = False
    Board.MnuThreatOff.Enabled = False
    Board.MnuThreatOff.Checked = True
End If

If Choice <> "Whale" And Choice <> "Maka" And Choice <> "Tai" And Choice <> "DaiDai" And Choice <> "Tori" And Choice <> "Micro" Then
    If AutoPromote = 1 Then
        Board.MnuAutoOn.Enabled = False
        Board.MnuAutoOn.Checked = True
        Board.MnuAutoOff.Enabled = True
        Board.MnuAutoOff.Checked = False
    Else
        Board.MnuAutoOn.Enabled = True
        Board.MnuAutoOn.Checked = False
        Board.MnuAutoOff.Enabled = False
        Board.MnuAutoOff.Checked = True
    End If
End If

If Eval = 1 Then
    Board.MnuEvalOn.Enabled = False
    Board.MnuEvalOn.Checked = True
    Board.MnuEvalOff.Enabled = True
    Board.MnuEvalOff.Checked = False
Else
    Board.MnuEvalOn.Enabled = True
    Board.MnuEvalOn.Checked = False
    Board.MnuEvalOff.Enabled = False
    Board.MnuEvalOff.Checked = True
End If

If Choice = "Tenjiku" Then Board.MnuEvalOn.Enabled = False
If Choice = "Tenjiku" Then
    If LionHawkVer = 1 Then
        Board.MnuLVer1.Enabled = False
        Board.MnuLVer1.Checked = True
        Board.MnuLVer2.Enabled = True
        Board.MnuLVer2.Checked = False
    Else
        Board.MnuLVer1.Enabled = True
        Board.MnuLVer1.Checked = False
        Board.MnuLVer2.Enabled = False
        Board.MnuLVer2.Checked = True
    End If
End If
If Choice = "Maka" Or Choice = "Tai" Then
    If TeachVer = 1 Then
        Board.MnuVer1.Enabled = False
        Board.MnuVer1.Checked = True
        Board.MnuVer2.Enabled = True
        Board.MnuVer2.Checked = False
    Else
        Board.MnuVer1.Enabled = True
        Board.MnuVer1.Checked = False
        Board.MnuVer2.Enabled = False
        Board.MnuVer2.Checked = True
    End If
End If
If Notate = 1 Then
    Board.NotTop.Visible = True
    Board.NotSide.Visible = True
    Board.MnuNotOff.Enabled = True
    Board.MnuNotOff.Checked = False
    Board.MnuNotOn.Enabled = False
    Board.MnuNotOn.Checked = True
Else
    Board.NotTop.Visible = False
    Board.NotSide.Visible = False
    Board.MnuNotOff.Enabled = False
    Board.MnuNotOff.Checked = True
    Board.MnuNotOn.Enabled = True
    Board.MnuNotOn.Checked = False
End If
SetDifficulty

End Sub

Sub ConfigLoad2()

If Choice = "Tenjiku" Then Computer = "None"
If Computer = "White" Or Computer = "Both" Then
    Board.MnuWhitePlayer.Enabled = True
    Board.MnuWhitePlayer.Checked = False
    Board.MnuWhiteComp.Enabled = False
    Board.MnuWhiteComp.Checked = True
    Board.MnuBlackPlayer.Enabled = False
    Board.MnuBlackPlayer.Checked = True
    Board.MnuBlackComp.Enabled = True
    Board.MnuBlackComp.Checked = False
End If
If Computer = "Black" Then
    Board.MnuWhitePlayer.Enabled = False
    Board.MnuWhitePlayer.Checked = True
    Board.MnuWhiteComp.Enabled = True
    Board.MnuWhiteComp.Checked = False
    Board.MnuBlackPlayer.Enabled = True
    Board.MnuBlackPlayer.Checked = False
    Board.MnuBlackComp.Enabled = False
    Board.MnuBlackComp.Checked = True
End If
If Computer = "" Or Computer = "None" Then
    Board.MnuWhitePlayer.Enabled = False
    Board.MnuWhitePlayer.Checked = True
    Board.MnuWhiteComp.Enabled = True
    Board.MnuWhiteComp.Checked = False
    Board.MnuBlackPlayer.Enabled = False
    Board.MnuBlackPlayer.Checked = True
    Board.MnuBlackComp.Enabled = True
    Board.MnuBlackComp.Checked = False
End If
If Choice = "Tenjiku" Then
    Eval = 0
    Board.MnuWhiteComp.Enabled = False
    Board.MnuBlackComp.Enabled = False
End If
End Sub

Sub ConfigSave()

Response% = MsgBox("Do you wish to save your Game Preferences?", 36)
If Response% = 6 Then
    Open Direct + "\" + "Shogi.cfg" For Output As #4
    Write #4, SeeMove, Timing, Computer, Threat, AutoPromote, Notate, LionHawkVer, TeachVer, Eval, Grade, ShowLast
    Close #4
End If
End Sub

Sub ConsiderMate()

BestTally(0) = -999999: CompMove = 0: Influence = 3: Evaluate = 1
MakeMap
If Turn = "Black" Then
    Steps = -1
    StartAA = LegalMoves
    EndAA = 1
Else
    Steps = 1
    StartAA = 1
    EndAA = LegalMoves
End If
For AA = StartAA To EndAA Step Steps
    WhiteTally = 0: BlackTally = 0
    DoEvents
    Evaluate = 1
    For JJ = 1 To BoardSizeY
        For KK = 1 To BoardSizeX
            Squares(KK, JJ) = Comp(KK, JJ)
        Next KK
    Next JJ
    InitFile = CompLegal(AA).StartFile
    InitRank = CompLegal(AA).StartRank
    CompFile = CompLegal(AA).EndFile
    CompRank = CompLegal(AA).EndRank
    Evaluate = 0
    FindInfluence
    If InitFile <> 0 Then Squares(InitFile, InitRank) = 0
    Squares(CompFile, CompRank) = CompLegal(AA).EndPiece
    Evaluate = 1
    For PP = 1 To Changed
        InitFile = Clearing(PP).File
        InitRank = Clearing(PP).Rank
        If Squares(InitFile, InitRank) <> 0 Then Validate
    Next PP
    Evaluate = 0
    For DD = 1 To BoardSizeY
        For EE = 1 To BoardSizeX
            If Squares(EE, DD) <> 0 Then
                If BanMap(EE, DD).WhiteNum > 0 And (Squares(EE, DD) = 1 Or (Squares(EE, DD) > 0 And BlackKing = 1 And (Pieces(Abs(Squares(EE, DD))).Name = "Crown Prince" Or Pieces(Abs(Squares(EE, DD))).Name = "Prince"))) Then BlackTally = -99999
                If BanMap(EE, DD).BlackNum > 0 And (Squares(EE, DD) = -1 Or (Squares(EE, DD) < 0 And WhiteKing = 1 And (Pieces(Abs(Squares(EE, DD))).Name = "Crown Prince" Or Pieces(Abs(Squares(EE, DD))).Name = "Prince"))) Then WhiteTally = -99999
            End If
        Next EE
    Next DD
    If Turn = "White" And WhiteTally = 0 Then BestTally(0) = 0: Exit Sub
    If Turn = "Black" And BlackTally = 0 Then BestTally(0) = 0: Exit Sub
    RestoreMap
Next AA
LegalMoves = 0
End Sub

Sub ConsiderMove()

' Evaluate Legal Moves

BestTally(0) = -999999: CompMove = 0: Influence = 3: Evaluate = 1
If Level > 0 Then
    For BB = 1 To Level + 1
        BestTally(BB) = -999999
        OldKingTally(BB) = 0
        ECapture(BB).Piece = 0
    Next BB
End If
MakeMap
For AA = 1 To LegalMoves
    KingTally(AA) = 0: WhiteTally = 0: BlackTally = 0
    DoEvents
    Evaluate = 1
    For JJ = 1 To BoardSizeY
        For KK = 1 To BoardSizeX
            Squares(KK, JJ) = Comp(KK, JJ)
        Next KK
    Next JJ
    InitFile = CompLegal(AA).StartFile
    InitRank = CompLegal(AA).StartRank
    CompFile = CompLegal(AA).EndFile
    CompRank = CompLegal(AA).EndRank
    If Choice = "Maka" Or Choice = "Tai" Then
        If Turn = "Black" And Pieces(Abs(Squares(InitFile, InitRank))).Name = "Emperor" Then BlackTally = BlackTally - 20
        If Turn = "White" And Pieces(Abs(Squares(InitFile, InitRank))).Name = "Emperor" Then WhiteTally = WhiteTally - 20
    End If
    If Choice = "Shogi" And TurnCount <= 1 Then
        If InitFile = 6 And InitRank = 1 Then KingTally(AA) = KingTally(AA) - 5
        If InitFile = 5 And InitRank = 1 Then KingTally(AA) = KingTally(AA) - 2
        If (InitRank = 3 Or InitRank = 7) Then KingTally(AA) = KingTally(AA) + 1
        If InitFile = 4 And InitRank = 9 Then KingTally(AA) = KingTally(AA) - 5
        If InitFile = 5 And InitRank = 9 Then KingTally(AA) = KingTally(AA) - 2
        If (InitFile = 2 And InitRank = 3) Or (InitFile = 8 And InitRank = 7) Then KingTally(AA) = KingTally(AA) + 4
    End If
    If Drop = 1 And Level = 0 Then
        If Turn = "Black" And Squares(CompFile, CompRank) < 0 Then
            If Pieces(Abs(Squares(CompFile, CompRank))).Promotes = 0 And Pieces(Abs(Squares(CompFile, CompRank))).PrGraphic > 0 Then BlackTally = BlackTally + (Pieces(Pieces(Abs(Squares(CompFile, CompRank))).PrGraphic).Value * 10) Else BlackTally = BlackTally + (Pieces(Abs(Squares(CompFile, CompRank))).Value * 10)
        End If
        If Turn = "White" And Squares(CompFile, CompRank) > 0 Then
            If Pieces(Abs(Squares(CompFile, CompRank))).Promotes = 0 And Pieces(Abs(Squares(CompFile, CompRank))).PrGraphic > 0 Then WhiteTally = WhiteTally + (Pieces(Pieces(Abs(Squares(CompFile, CompRank))).PrGraphic).Value * 10) Else WhiteTally = WhiteTally + (Pieces(Abs(Squares(CompFile, CompRank))).Value * 10)
        End If
    End If
    If Drop = 1 And Level > 1 Then
        If Turn = "Black" And Squares(CompFile, CompRank) < 0 Then
            If Pieces(Abs(Squares(CompFile, CompRank))).Promotes = 0 And Pieces(Abs(Squares(CompFile, CompRank))).PrGraphic > 0 Then KingTally(AA) = KingTally(AA) + (Pieces(Pieces(Abs(Squares(CompFile, CompRank))).PrGraphic).Value * 10) Else KingTally(AA) = KingTally(AA) + (Pieces(Abs(Squares(CompFile, CompRank))).Value * 10)
        End If
        If Turn = "White" And Squares(CompFile, CompRank) > 0 Then
            If Pieces(Abs(Squares(CompFile, CompRank))).Promotes = 0 And Pieces(Abs(Squares(CompFile, CompRank))).PrGraphic > 0 Then KingTally(AA) = KingTally(AA) + (Pieces(Pieces(Abs(Squares(CompFile, CompRank))).PrGraphic).Value * 10) Else KingTally(AA) = KingTally(AA) + (Pieces(Abs(Squares(CompFile, CompRank))).Value * 10)
        End If
    End If
    If (TurnCount < 4 And BoardSizeY > 7) Or TurnCount < 2 Then KingTally(AA) = KingTally(AA) + 4 - (Rnd * 8)
    KingSafety
    Evaluate = 0
    FindInfluence
    If InitFile <> 0 Then Squares(InitFile, InitRank) = 0
    If ExtraCapture(AA).Piece <> 0 Then Squares(ExtraCapture(AA).File, ExtraCapture(AA).Rank) = 0
    Squares(CompFile, CompRank) = CompLegal(AA).EndPiece
    Evaluate = 1
    For PP = 1 To Changed
        InitFile = Clearing(PP).File
        InitRank = Clearing(PP).Rank
        If Squares(InitFile, InitRank) <> 0 Then Validate
    Next PP
    Evaluate = 0
    PawnMates
    If Turn = "Black" And BanMap(CompFile, CompRank).WhiteNum > 0 And BanMap(CompFile, CompRank).BlackNum = 0 And Comp(CompFile, CompRank) >= 0 Then BlackTally = BlackTally - 999
    If Turn = "White" And BanMap(CompFile, CompRank).BlackNum > 0 And BanMap(CompFile, CompRank).WhiteNum = 0 And Comp(CompFile, CompRank) <= 0 Then WhiteTally = WhiteTally - 999
    For DD = 1 To BoardSizeY
        For EE = 1 To BoardSizeX
            If Squares(EE, DD) <> 0 Then
                If Squares(EE, DD) = 1 Or (Squares(EE, DD) > 1 And Pieces(Abs(Squares(EE, DD))).Name = "Emperor") Or (Squares(EE, DD) > 0 And BlackKing = 1 And (Pieces(Abs(Squares(EE, DD))).Name = "Crown Prince" Or Pieces(Abs(Squares(EE, DD))).Name = "Prince")) Then BlackTally = BlackTally + 9999
                If Squares(EE, DD) = -1 Or (Squares(EE, DD) < -1 And Pieces(Abs(Squares(EE, DD))).Name = "Emperor") Or (Squares(EE, DD) < 0 And WhiteKing = 1 And (Pieces(Abs(Squares(EE, DD))).Name = "Crown Prince" Or Pieces(Abs(Squares(EE, DD))).Name = "Prince")) Then WhiteTally = WhiteTally + 9999
            End If
            If ExtraCapture(AA).Piece = 0 Or ExtraCapture(AA).File <> EE Or ExtraCapture(AA).Rank <> DD Then
                If Squares(EE, DD) < 0 Then WhiteTally = WhiteTally + (Pieces(Abs(Squares(EE, DD))).Value * 10)
                If Squares(EE, DD) > 0 Then BlackTally = BlackTally + (Pieces(Abs(Squares(EE, DD))).Value * 10)
            End If
            If Choice = "Tai" Or Choice = "Maka" Then
                If Turn = "Black" Then
                    If Squares(EE, DD) > 0 Then
                        If BlackEmperor = 0 And WhiteEmperor = 1 And BanMap(EE, DD).BlackNum = 0 Then BlackTally = BlackTally - (Pieces(Abs(Squares(EE, DD))).Value * 10)
                        If Pieces(Abs(Squares(EE, DD))).Name = "Emperor" And BanMap(EE, DD).WhiteNum > 0 Then BlackTally = BlackTally - (Pieces(Abs(Squares(EE, DD))).Value * 20)
                        If Pieces(Abs(Squares(EE, DD))).Name = "Emperor" And WhiteEmperor = 1 And (EE <> WhiteEmpX Or DD <> WhiteEmpY) And BanMap(EE, DD).BlackNum = 0 Then BlackTally = BlackTally - (Pieces(Abs(Squares(EE, DD))).Value * 20)
                    End If
                Else
                    If Squares(EE, DD) < 0 Then
                        If WhiteEmperor = 0 And BlackEmperor = 1 And BanMap(EE, DD).WhiteNum = 0 Then WhiteTally = WhiteTally - (Pieces(Abs(Squares(EE, DD))).Value * 10)
                        If Pieces(Abs(Squares(EE, DD))).Name = "Emperor" And BanMap(EE, DD).BlackNum > 0 Then WhiteTally = WhiteTally - (Pieces(Abs(Squares(EE, DD))).Value * 20)
                        If Pieces(Abs(Squares(EE, DD))).Name = "Emperor" And BlackEmperor = 1 And (EE <> BlackEmpX Or DD <> BlackEmpY) And BanMap(EE, DD).WhiteNum = 0 Then WhiteTally = WhiteTally - (Pieces(Abs(Squares(EE, DD))).Value * 20)
                    End If
                End If
            End If
            If BanMap(EE, DD).BlackNum = 0 And BanMap(EE, DD).WhiteNum > 0 Then
                WhiteTally = 1 + Abs((BoardSizeY / 2) + 0.5 - DD) / 2 + WhiteTally
                If Squares(EE, DD) < 0 Then WhiteTally = WhiteTally + 1
                If Squares(EE, DD) > 0 And Turn = "Black" Then BlackTally = BlackTally - (Pieces(Abs(Squares(EE, DD))).Value * 10)
                If Squares(EE, DD) = 1 And Turn = "Black" And Level > 1 Then KingTally(AA) = -99999
                If Squares(EE, DD) > 0 And Turn = "Black" And Level = 0 Then BlackTally = BlackTally + (Pieces(Abs(Squares(EE, DD))).Value)
            End If
            If BanMap(EE, DD).WhiteNum = 0 And BanMap(EE, DD).BlackNum > 0 Then
                BlackTally = 1 + Abs((BoardSizeY / 2) + 0.5 - DD) / 2 + BlackTally
                If Squares(EE, DD) > 0 Then BlackTally = BlackTally + 1
                If Squares(EE, DD) = -1 And Turn = "White" And Level > 1 Then KingTally(AA) = -99999
                If Squares(EE, DD) < 0 And Turn = "White" Then WhiteTally = WhiteTally - (Pieces(Abs(Squares(EE, DD))).Value * 10)
                If Squares(EE, DD) < 0 And Turn = "White" And Level = 0 Then WhiteTally = WhiteTally + (Pieces(Abs(Squares(EE, DD))).Value)
            End If
            If BanMap(EE, DD).WhiteNum > 0 And BanMap(EE, DD).BlackNum > 0 Then
                If Squares(EE, DD) > 0 And Turn = "Black" Then
                    LionAttack = 0
                    If (Choice = "Chu" Or Choice = "Dai" Or Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tenjiku" Or Choice = "Tai") Then
                        For JJJ = DD - 1 To DD + 1
                            For KKK = EE - 1 To EE + 1
                                If JJJ > 0 And JJJ < BoardSizeY And KKK > 0 And KKK < BoardSizeX Then
                                    If Squares(KKK, JJJ) < 0 Then
                                        If Pieces(Abs(Squares(KKK, JJJ))).special = "L" Then LionAttack = 1
                                    End If
                                End If
                            Next KKK
                        Next JJJ
                    End If
                    If LionAttack = 1 Then
                        BlackTally = BlackTally - (Pieces(Abs(Squares(EE, DD))).Value * 10)
                        LionAttack = 0
                    Else
                    For QQ = 1 To Attacker(EE, DD)
                        If BanMap(EE, DD).Info(QQ).Piece <> 0 Then
                            If BanMap(EE, DD).Info(QQ).Piece < 0 And (Pieces(Abs(BanMap(EE, DD).Info(QQ).Piece)).Value < LowWhite(EE, DD) Or LowWhite(EE, DD) = 0) Then
                                LowWhite(EE, DD) = Pieces(Abs(BanMap(EE, DD).Info(QQ).Piece)).Value
                                If Level < 2 Then LowWhite(EE, DD) = LowWhite(EE, DD) - 1
                            End If
                            If BanMap(EE, DD).WhiteNum > 1 And BanMap(EE, DD).Info(QQ).Piece > 0 And Level > 0 Then
                                If Pieces(Abs(BanMap(EE, DD).Info(QQ).Piece)).Value < LowBlack(EE, DD) Or LowBlack(EE, DD) = 0 Then LowBlack(EE, DD) = Pieces(Abs(BanMap(EE, DD).Info(QQ).Piece)).Value
                            End If
                        End If
                    Next QQ
                    BlackLoss = ((Pieces(Abs(Squares(EE, DD))).Value + LowBlack(EE, DD) - LowWhite(EE, DD)) * 10)
                    If Squares(EE, DD) = 1 Or Pieces(Abs(Squares(EE, DD))).Name = "Emperor" Or (BlackKing = 1 And Pieces(Abs(Squares(EE, DD))).Name = "Crown Prince" Or Pieces(Abs(Squares(EE, DD))).Name = "Prince") Then BlackLoss = 29999: If Level > 0 Then KingTally(AA) = -99999
                    If BlackLoss > HighBlackLoss Then HighBlackLoss = BlackLoss
                    End If
                End If
                If Squares(EE, DD) < -1 And Turn = "Black" Then BlackTally = BlackTally + (Pieces(Abs(Squares(EE, DD))).Value / 4)
                If Squares(EE, DD) < 0 And Turn = "White" Then
                    LionAttack = 0
                    If (Choice = "Chu" Or Choice = "Dai" Or Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tenjiku" Or Choice = "Tai") Then
                        For JJJ = DD - 1 To DD + 1
                            For KKK = EE - 1 To EE + 1
                                If JJJ > 0 And JJJ < BoardSizeY And KKK > 0 And KKK < BoardSizeX Then
                                    If Squares(KKK, JJJ) > 0 Then
                                        If Pieces(Abs(Squares(KKK, JJJ))).special = "L" Then LionAttack = 1
                                    End If
                                End If
                            Next KKK
                        Next JJJ
                    End If
                    If LionAttack = 1 Then
                        WhiteTally = WhiteTally - (Pieces(Abs(Squares(EE, DD))).Value * 10)
                        LionAttack = 0
                    Else
                    For QQ = 1 To Attacker(EE, DD)
                        If BanMap(EE, DD).Info(QQ).Piece <> 0 Then
                            If BanMap(EE, DD).Info(QQ).Piece > 0 And (Pieces(Abs(BanMap(EE, DD).Info(QQ).Piece)).Value < LowBlack(EE, DD) Or LowBlack(EE, DD) = 0) Then
                                LowBlack(EE, DD) = Pieces(Abs(BanMap(EE, DD).Info(QQ).Piece)).Value
                                If Level < 2 Then LowWhite(EE, DD) = LowWhite(EE, DD) - 1
                            End If
                            If BanMap(EE, DD).BlackNum > 1 And BanMap(EE, DD).Info(QQ).Piece < 0 And Level > 0 Then
                                If Pieces(Abs(BanMap(EE, DD).Info(QQ).Piece)).Value < LowWhite(EE, DD) Or LowWhite(EE, DD) = 0 Then LowWhite(EE, DD) = Pieces(Abs(BanMap(EE, DD).Info(QQ).Piece)).Value
                            End If
                        End If
                    Next QQ
                    WhiteLoss = ((Pieces(Abs(Squares(EE, DD))).Value + LowWhite(EE, DD) - LowBlack(EE, DD)) * 10)
                    If Squares(EE, DD) = -1 Or Pieces(Abs(Squares(EE, DD))).Name = "Emperor" Or (WhiteKing = 1 And Pieces(Abs(Squares(EE, DD))).Name = "Crown Prince" Or Pieces(Abs(Squares(EE, DD))).Name = "Prince") Then WhiteLoss = 29999: If Level > 0 Then KingTally(AA) = -99999
                    If WhiteLoss > HighWhiteLoss Then HighWhiteLoss = WhiteLoss
                End If
                End If
                If Squares(EE, DD) > 1 And Turn = "White" Then WhiteTally = WhiteTally + (Pieces(Abs(Squares(EE, DD))).Value / 4)
            End If
            File = EE: Rank = DD: CompMate
            LowWhite(EE, DD) = 0: LowBlack(EE, DD) = 0
        Next EE
    Next DD
    If Drop = 1 Then
        For FF = 1 To Capture
            BlackTally = BlackTally + (Pieces(Abs(CapRef(FF))).Value * 10.5) * (InHand(FF))
            WhiteTally = WhiteTally + (Pieces(Abs(CapRef(FF + Capture))).Value * 10.5) * (InHand(FF + Capture))
        Next FF
        If CompLegal(AA).StartFile = 0 Then
            If Turn = "White" Then
                WhiteTally = WhiteTally - Pieces(Abs(CompLegal(AA).StartPiece)).Value * 10.5
            Else
                BlackTally = BlackTally - Pieces(Abs(CompLegal(AA).StartPiece)).Value * 10.5
            End If
        End If
    End If
    BlackTally = BlackTally - HighBlackLoss: HighBlackLoss = 0
    WhiteTally = WhiteTally - HighWhiteLoss: HighWhiteLoss = 0
    If Level > 0 And Rnd < 0.5 Then
        If Turn = "White" Then WhiteTally = WhiteTally + Int(Rnd * 2) + 1 Else BlackTally = BlackTally + Int(Rnd * 2) + 1
    End If
    If Level > 1 Then
        If Turn = "White" And (WhiteTally - BlackTally) + KingTally(AA) > BestTally(TestDepth) Then
            BestTally(Level + 1) = (WhiteTally - BlackTally) + KingTally(AA): BestMove = AA: ReorderMoves
        End If
        If Turn = "Black" And (BlackTally - WhiteTally) + KingTally(AA) > BestTally(TestDepth) Then
            BestTally(Level + 1) = (BlackTally - WhiteTally) + KingTally(AA): BestMove = AA: ReorderMoves
        End If
    Else
        If Level = 1 Then
            If Turn = "White" And WhiteTally - BlackTally + KingTally(AA) > BestTally(1) Then
                BestTally(1) = WhiteTally - BlackTally + KingTally(AA): BestMove = AA
                If (Choice = "Chu" Or Choice = "Dai" Or Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tenjiku" Or Choice = "Tai") And ExtraCapture(AA).Piece <> 0 Then
                    LionVictim.Piece = ExtraCapture(AA).Piece
                    LionVictim.File = ExtraCapture(AA).File
                    LionVictim.Rank = ExtraCapture(AA).Rank
                Else
                    LionVictim.Piece = 0
                End If
            End If
            If Turn = "Black" And BlackTally - WhiteTally + KingTally(AA) > BestTally(1) Then
                BestTally(1) = BlackTally - WhiteTally + KingTally(AA): BestMove = AA
                If (Choice = "Chu" Or Choice = "Dai" Or Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tenjiku" Or Choice = "Tai") And ExtraCapture(AA).Piece <> 0 Then
                    LionVictim.Piece = ExtraCapture(AA).Piece
                    LionVictim.File = ExtraCapture(AA).File
                    LionVictim.Rank = ExtraCapture(AA).Rank
                Else
                    LionVictim.Piece = 0
                End If
            End If
        Else
            If Turn = "White" And WhiteTally - BlackTally + KingTally(AA) > BestTally(0) Then
                BestTally(0) = WhiteTally - BlackTally + KingTally(AA)
            End If
            If Turn = "Black" And BlackTally - WhiteTally + KingTally(AA) > BestTally(0) Then
                BestTally(0) = BlackTally - WhiteTally + KingTally(AA)
            End If
        End If
    End If
    RestoreMap
    ExtraCapture(AA).Piece = 0
Next AA

End Sub

Sub Convert()

ClearLegal
DropTest = 0: Strip = 0: NoStrip = 0
I = TurnCount + 1
ShortScore(I) = CMove$
K = Len(ShortScore(I))
If InStr(ShortScore(I), "*") = 0 Or Right(ShortScore(I), 1) = "*" Then
    For AB = 1 To BoardSizeY
        For CD = 1 To BoardSizeX
            If Squares(CD, AB) = Score(TurnCount).IDStart And Score(TurnCount).IDStart <> 0 And (File <> CD Or Rank <> AB) Then
                If Pieces(Abs(Squares(CD, AB))).sname = Pieces(Abs(Score(TurnCount).IDStart)).sname Then
                    FirstFile = CD: FirstRank = AB
                    TestOther
                End If
            End If
        Next CD
    Next AB
    If Testing123 <> 1 Then
    For J = 1 To K
        If Mid(ShortScore(I), J, 1) > Chr$(47) And Mid(ShortScore(I), J, 1) < Chr$(58) And NoStrip = 0 And Strip = 0 Then
        Strip = 1
        LeftBit = Left(ShortScore(I), J - 1)
        End If
        If Strip = 1 And Mid(ShortScore(I), J, 1) > Chr$(96) And Mid(ShortScore(I), J, 1) < Chr$(123) Then
        NoStrip = 1: Strip = 0
        RightBit = Right(ShortScore(I), K - J)
        End If
    Next J
    ShortScore(I) = LeftBit + RightBit
    End If
    Testing123 = 0
End If
 
End Sub

Sub ConvertScore()

For I = 1 To TurnCount
    Strip = 0: NoStrip = 0
    ShortScore(I) = Score(I).Caption
    For J = 1 To Len(ShortScore(I))
      If Mid(ShortScore(I), J, 1) = " " Then ShortScore(I) = Right(ShortScore(I), Len(ShortScore(I)) - J): OldScore = 1
    Next J
    If OldScore = 1 Then
        K = Len(ShortScore(I))
        If InStr(ShortScore(I), "*") = 0 Or Right(ShortScore(I), 1) = "*" Then
            For J = 1 To K
                If Mid(ShortScore(I), J, 1) > Chr$(47) And Mid(ShortScore(I), J, 1) < Chr$(58) And NoStrip = 0 And Strip = 0 Then
                    Strip = 1
                    LeftBit = Left(ShortScore(I), J - 1)
                End If
                If Strip = 1 And Mid(ShortScore(I), J, 1) > Chr$(96) And Mid(ShortScore(I), J, 1) < Chr$(123) Then
                    NoStrip = 1: Strip = 0
                    RightBit = Right(ShortScore(I), K - J)
                End If
            Next J
            ShortScore(I) = LeftBit + RightBit
        End If
    End If
    OldScore = 0
    Score(I).Caption = ShortScore(I)
Next I
End Sub

Sub DiagramDrop()

BlackDrop(1) = "|": BlackDrop(2) = "|": Z = 1
If Reverse = 0 Then
    J = 1: K = Capture
    L = K + 1: M = K * 2
Else
    L = 1: M = Capture
    J = M + 1: K = M * 2
End If
For I = J To K
    If InHand(I) > 0 Then
        BlackDrop(Z) = BlackDrop(Z) + " " + Left(Pieces(Abs(CapRef(I))).sname, Len(Trim$(Pieces(Abs(CapRef(I))).sname)))
        If InHand(I) > 1 Then BlackDrop(Z) = BlackDrop(Z) + "x" + Trim$(Str$(InHand(I)))
        If Len(BlackDrop(Z)) > 12 Then Z = 2
    End If
Next I
WhiteDrop(2) = "|": WhiteDrop(1) = "|": Z = 1
For I = L To M
    If InHand(I) > 0 Then
        WhiteDrop(Z) = WhiteDrop(Z) + " " + Left(Pieces(Abs(CapRef(I))).sname, Len(Trim$(Pieces(Abs(CapRef(I))).sname)))
        If InHand(I) > 1 Then WhiteDrop(Z) = WhiteDrop(Z) + "x" + Trim$(Str$(InHand(I)))
        If Len(WhiteDrop(Z)) > 13 Then Z = 2
    End If
Next I
If WhiteDrop(1) = "|" Then WhiteDrop(1) = WhiteDrop(1) + " Nothing"
If BlackDrop(1) = "|" Then BlackDrop(1) = BlackDrop(1) + " Nothing"
For I = 1 To 2
    WhiteDrop(I) = WhiteDrop(I) + Space(17 - Len(WhiteDrop(I))) + "|"
    BlackDrop(I) = BlackDrop(I) + Space(17 - Len(BlackDrop(I))) + "|"
Next I
End Sub

Sub DiagramFile()

On Error Resume Next
Board.CMDiagram.DialogTitle = "Create Text Diagram"
Board.CMDiagram.Flags = &H400& Or &H800& Or &H4&
Board.CMDiagram.Action = 2
If Err = 32755 Then Exit Sub
Saved$ = Board.CMDiagram.FileName

Open Saved$ For Output As #3

If GameName = "Whale" Or GameName = "Early" Or GameName = "Bird" Or GameName = "Micro" Or GameName = "Mini" Or GameName = "" Then Short = 1 Else Short = 0
If Drop = 1 Then DiagramDrop
DropStart = 0: DropEnd = 0
If Drop = 1 Then
    DropStart = 1
    DropEnd = BoardSizeY - 1
End If
If GameName <> "" Then
    Print #3, GameName; " Shogi"
    For I = 1 To Len(GameName) + 6
        Print #3, "=";
    Next I
End If
Print #3,
Print #3, " ";
For I = BoardSizeX To 1 Step -1
    If I < 10 Then Print #3, " ";
    If Short = 0 Then Print #3, " ";
    Print #3, I; " ";
Next I
Print #3,
For J = 1 To BoardSizeY
    Print #3, "+";
    For I = 1 To BoardSizeX - 1
        If Short = 0 Then Print #3, "------"; Else Print #3, "-----";
    Next I
    If Short = 0 Then Print #3, "-----+"; Else Print #3, "----+";
    If Drop = 1 Then
        If J = DropStart Then Print #3, "      White in hand:";
        If J = DropStart + 1 Then Print #3, "      "; WhiteDrop(1);
        If J = DropEnd + 1 Then Print #3, "      "; BlackDrop(1);
        If J = DropEnd Then Print #3, "      Black in hand:";
        If J = DropStart + 2 Then Print #3, "      +----------------+";
    End If
    Print #3,
    For I = 1 To BoardSizeX
        Print #3, "|";
        If Squares(I, J) <> 0 Then
            If Squares(I, J) > 0 Then Print #3, " b"; Else Print #3, " w";
            Print #3, Left$(Pieces(Abs(Squares(I, J))).sname, 3 - Short);
        Else
            If Short = 0 Then Print #3, "     "; Else Print #3, "    ";
        End If
    Next I
    Print #3, "| "; Chr$(96 + J);
    If J = DropStart Or J = DropEnd Then Print #3, "    +----------------+";
    If J = DropStart + 1 Then Print #3, "    "; WhiteDrop(2);
    If J = DropEnd + 1 Then Print #3, "    "; BlackDrop(2);
    Print #3,
Next J
Print #3, "+";
For I = 1 To BoardSizeX - 1
    If Short = 0 Then Print #3, "------"; Else Print #3, "-----";
Next I
If Short = 0 Then Print #3, "-----+"; Else Print #3, "----+";
If DropEnd > 0 Then Print #3, "      +----------------+";
Print #3,
Print #3,
Print #3, Turn; " to move."
Board.Caption = "Diagram text file " + Board.CMDiagram.FileName + " created.": Notice = 1
Close #3
End Sub

Sub DiagramSmall()

On Error Resume Next
Board.CMDiagram.DialogTitle = "Create Small Text Diagram"
Board.CMDiagram.Flags = &H400& Or &H800& Or &H4&
Board.CMDiagram.Action = 2
If Err = 32755 Then Exit Sub
Saved$ = Board.CMDiagram.FileName

Open Saved$ For Output As #3

If GameName = "Whale" Or GameName = "Early" Or GameName = "Bird" Or GameName = "Micro" Or GameName = "Mini" Or GameName = "" Then Short = 1 Else Short = 0
If Drop = 1 Then DiagramDrop
DropStart = 0: DropEnd = 0
If Drop = 1 Then
    DropStart = 1
    DropEnd = BoardSizeY - 1
End If
If GameName <> "" Then
    Print #3, GameName; " Shogi"
    For I = 1 To Len(GameName) + 6
        Print #3, "=";
    Next I
End If
Print #3,
For I = BoardSizeX To 1 Step -1
    If I < 10 Then Print #3, " ";
    If Short = 0 Then Print #3, " ";
    Print #3, Trim$(Str$(I));
    Print #3, " ";
Next I
Print #3,
Print #3, "+";
For I = 1 To BoardSizeX - 1
    If Short = 0 Then Print #3, "----"; Else Print #3, "---";
Next I
If Short = 0 Then Print #3, "----+"; Else Print #3, "---+";
If DropStart = 1 Then Print #3, "    White in hand:";
Print #3,
For J = 1 To BoardSizeY
    Print #3, "|";
    For I = 1 To BoardSizeX
        If Squares(I, J) <> 0 Then
            If Squares(I, J) > 0 Then Print #3, "b"; Else Print #3, "w";
            Print #3, Left$(Pieces(Abs(Squares(I, J))).sname, 3 - Short);
        Else
            If Short = 0 Then Print #3, " *  "; Else Print #3, " * ";
        End If
    Next I
    Print #3, "|"; Chr$(96 + J);
    If J = DropStart Then Print #3, "  "; Mid(WhiteDrop(1), 2, 16);
    If J = DropStart + 1 Then Print #3, "  "; Mid(WhiteDrop(2), 2, 16);
    If J = DropEnd + 1 Then Print #3, "  "; Mid(BlackDrop(1), 2, 16);
    If J = DropEnd Then Print #3, "   Black in hand:";
    Print #3,
Next J
Print #3, "+";
For I = 1 To BoardSizeX - 1
    If Short = 0 Then Print #3, "----"; Else Print #3, "---";
Next I
If Short = 0 Then Print #3, "----+"; Else Print #3, "---+";
If DropEnd > 0 Then Print #3, "    "; Mid(BlackDrop(2), 2, 16);
Print #3,
Print #3, Turn; " to move."
Board.Caption = "Diagram text file " + Board.CMDiagram.FileName + " created.": Notice = 1
Close #3

End Sub

Sub DisplayEmperor()

For K = 1 To BoardSizeY
    For J = 1 To BoardSizeX
        Board.ForeColor = &HFF8080
        Legal(J, K) = 1: L = 0
        If Turn = "Black" And Squares(J, K) < 0 And ((Camps(J, K) = 1 Or Camps(J, K) = 3) Or WhiteEmperor = 1) Then Legal(J, K) = 0
        If Turn = "White" And Squares(J, K) > 0 And (Camps(J, K) > 1 Or BlackEmperor = 1) Then Legal(J, K) = 0
        If Turn = "Black" And Squares(J, K) < 0 And Legal(J, K) = 1 Then Board.ForeColor = &HC0
        If Turn = "White" And Squares(J, K) > 0 And Legal(J, K) = 1 Then Board.ForeColor = &HC0
        If FirstInitRank = K And FirstInitFile = J Then Legal(J, K) = 0
        If Squares(J, K) <> 0 Then
            If Pieces(Abs(Squares(J, K))).Name = "Emperor" And Sgn(Squares(J, K)) <> Sgn(Squares(FirstInitFile, FirstInitRank)) Then
                NewRank = K: NewFile = J: Legal(J, K) = 1: CheckEmperor
                K = NewRank: J = NewFile
                If Legal(J, K) = 1 Then Board.ForeColor = &HC0
            End If
        End If
        If SeeMove = 1 And Legal(J, K) = 1 Then
            If Squares(J, K) = 0 Then
                If Reverse = 0 Then
                    Board.Line (XStart + ((J - 1) * Pixels), 11 + ((K - 1) * Pixels))-(XStart + (J * Pixels) - 2, 9 + (K * Pixels)), , BF
                Else
                    Board.Line (XStart + ((BoardSizeX - J) * Pixels), 11 + ((BoardSizeY - K) * Pixels))-(XStart - 2 + ((BoardSizeX - J + 1) * Pixels), 9 + ((BoardSizeY - K + 1) * Pixels) + L), , BF
                End If
            Else
                For EF = 2 To Pixels
                    If Reverse = 0 Then
                        If Squares(J, K) > 0 Then
                           Board.Line (XStart + ((J - 1) * Pixels) + EF - 2, 11 + ((K - 1) * Pixels))-(XStart + ((J - 1) * Pixels) + EF - 2, 11 + ((K - 1) * Pixels) + PieceMask(Pieces(Abs(Squares(J, K))).Mask, EF) + 1)
                        Else
                           Board.Line (XStart + ((J - 1) * Pixels) + (Pixels - EF), 9 + (K * Pixels))-(XStart + ((J - 1) * Pixels) + (Pixels - EF), 8 + (K * Pixels) - (PieceMask(Pieces(Abs(Squares(J, K))).Mask, EF)))
                        End If
                    Else
                        If Squares(J, K) > 0 Then
                           Board.Line (XStart + ((BoardSizeX - J) * Pixels + (Pixels - EF)), 8 + ((BoardSizeY - K + 1) * Pixels) + 1)-(XStart + ((BoardSizeX - J) * Pixels) + (Pixels - EF), 8 + ((BoardSizeY - K + 1) * Pixels) - PieceMask(Pieces(Abs(Squares(J, K))).Mask, EF))
                        Else
                           Board.Line (XStart + ((BoardSizeX - J) * Pixels) + EF - 2, 10 + ((BoardSizeY - K) * Pixels) + 1)-(XStart + ((BoardSizeX - J) * Pixels) + EF - 2, 12 + ((BoardSizeY - K) * Pixels) + PieceMask(Pieces(Abs(Squares(J, K))).Mask, EF))
                        End If
                    End If
                Next EF
            End If
        End If
        Camps(J, K) = 0
    Next J
Next K
Influence = 0
Board.ForeColor = &H0&
Board.FillColor = &HFFFFFF

End Sub

Sub DisplayTerritory()

For K = 1 To BoardSizeY
    For J = 1 To BoardSizeX
        L = 0
        Select Case Choice
            Case "Heian", "Chu", "Dai", "Tenjiku": L = 1
        End Select
        Select Case Camps(J, K)
            Case 1: Board.ForeColor = &HFFFFFF
            Case 2: Board.ForeColor = &H606060
            Case 3: Board.ForeColor = &HC0C0C0
        End Select
        If Camps(J, K) > 0 Then
            If Squares(J, K) = 0 Then
                If Reverse = 0 Then
                    Board.Line (XStart + L + ((J - 1) * Pixels), 11 + L + ((K - 1) * Pixels))-(XStart + (J * Pixels) - 2 + L, 9 + L + (K * Pixels)), , BF
                Else
                    Board.Line (XStart + L + ((BoardSizeX - J) * Pixels), 11 + ((BoardSizeY - K) * Pixels) + L)-(XStart - 2 + L + ((BoardSizeX - J + 1) * Pixels), 9 + ((BoardSizeY - K + 1) * Pixels) + L), , BF
                End If
            Else
                If Squares(J, K) > 0 And Camps(J, K) = 1 Then Board.ForeColor = &HFF8080
                If Squares(J, K) < 0 And Camps(J, K) = 2 Then Board.ForeColor = &HFF8080
                If Squares(J, K) < 0 Then
                    If (Squares(J, K) = -1 Or Pieces(Abs(Squares(J, K))).Name = "Crown Prince" Or Pieces(Abs(Squares(J, K))).Name = "Prince") And Camps(J, K) > 1 Then Board.ForeColor = &HC0&
                Else
                    If (Squares(J, K) = 1 Or Pieces(Abs(Squares(J, K))).Name = "Crown Prince" Or Pieces(Abs(Squares(J, K))).Name = "Prince") And (Camps(J, K) = 1 Or Camps(J, K) = 3) Then Board.ForeColor = &HC0&
                End If
                For EF = 2 To Pixels
                    If Reverse = 0 Then
                        If Squares(J, K) > 0 Then
                           Board.Line (XStart + ((J - 1) * Pixels) + EF - 2 + L, 11 + ((K - 1) * Pixels) + L)-(XStart + ((J - 1) * Pixels) + EF - 2 + L, 11 + ((K - 1) * Pixels) + PieceMask(Pieces(Abs(Squares(J, K))).Mask, EF) + 1)
                        Else
                           Board.Line (XStart + ((J - 1) * Pixels) + (Pixels - EF) + L, 9 + (K * Pixels) + L)-(XStart + ((J - 1) * Pixels) + (Pixels - EF) + L, 8 + (K * Pixels) - (PieceMask(Pieces(Abs(Squares(J, K))).Mask, EF) - (L * 2)))
                        End If
                    Else
                        If Squares(J, K) > 0 Then
                           Board.Line (XStart + ((BoardSizeX - J) * Pixels + (Pixels - EF)) + L, 8 + ((BoardSizeY - K + 1) * Pixels) + 1 + L)-(XStart + ((BoardSizeX - J) * Pixels) + (Pixels - EF) + L, 8 + ((BoardSizeY - K + 1) * Pixels) - PieceMask(Pieces(Abs(Squares(J, K))).Mask, EF) + (L * 2))
                        Else
                           Board.Line (XStart + ((BoardSizeX - J) * Pixels) + EF - 2 + L, 10 + ((BoardSizeY - K) * Pixels) + 1 + L)-(XStart + ((BoardSizeX - J) * Pixels) + EF - 2 + L, 12 + ((BoardSizeY - K) * Pixels) + PieceMask(Pieces(Abs(Squares(J, K))).Mask, EF))
                        End If
                    End If
                Next EF
            End If
        End If
        Camps(J, K) = 0
    Next J
Next K
Board.ForeColor = &H0&
Board.FillColor = &HFFFFFF
End Sub

Sub DolphinMove()

If (Squares(InitFile, InitRank) > 0 And InitRank = 1) Or (Squares(InitFile, InitRank) < 0 And InitRank = 6) Then
    Pieces(Abs(Squares(InitFile, InitRank))).Moves(7) = 64
    Pieces(Abs(Squares(InitFile, InitRank))).Moves(8) = 64
End If

End Sub

Sub DoubleMove()

ClearLegal
LionName$ = Pieces(Abs(Squares(File, Rank))).Name
Board.Caption = "Extra " + LionName$ + " move - Double Click on Piece to End Move."
LionPiece = I
Teach = Teach - 1
If Reverse = 0 Then
    Board.Frame.Move XStart + (File - 1) * Pixels, 11 + (Rank - 1) * Pixels
Else
    Board.Frame.Move XStart + (BoardSizeX - File) * Pixels, 11 + (BoardSizeY - Rank) * Pixels
End If
Board.Frame.Visible = True

End Sub

Sub DropPiece()

If NewButton = 1 Then
    Board.PieceID.Caption = ""
    Board.showpic(I).Drag 0
Else
    Board.PieceID.Caption = ""
    Board.PieceID.ForeColor = &HFF0000
    RightClick = 0
End If
If LegalMoves = 0 Then ClearLegal

End Sub

Sub DropPiece2()
If NewButton = 1 Then
    Board.PieceID.Caption = ""
    Board.HandPic(I).Drag 0
    If LegalMoves = 0 Then ClearLegal
Else
    Board.PieceID.Caption = ""
    Board.PieceID.ForeColor = &HFF0000
    If LegalMoves = 0 Then ClearLegal
End If
End Sub

Sub Emperor()

FirstInitFile = InitFile: FirstInitRank = InitRank: EmperorTest = 1
Influence = 2
For AB = 1 To BoardSizeY
    For CD = 1 To BoardSizeX
        If (Turn = "Black" And Squares(CD, AB) < 0) Or (Turn = "White" And Squares(CD, AB) > 0) Then
            InitFile = CD: InitRank = AB
            Validate
        End If
    Next CD
Next AB
DisplayEmperor
Influence = 0: EmperorTest = 0
InitRank = FirstInitRank: InitFile = FirstInitFile
End Sub

Sub EmperorCheck()

OldInfluence = Influence: OldCompMove = CompMove: OldSeeMove = SeeMove: SeeMove = 1
CompMove = 0: Influence = 2
For AB = 1 To BoardSizeY
   For CD = 1 To BoardSizeX
       InitFile = CD: InitRank = AB: Validate
   Next CD
Next AB
If Camps(BlackEmpX, BlackEmpY) = 0 Then
    If Turn = "White" Then
        Response% = MsgBox("You have left your Emperor in Check! ", 0, "Black")
    Else
        Board.PieceID.Caption = "Black Emperor is in Check!": Notice = 1
    End If
Else
    If Camps(WhiteEmpX, WhiteEmpY) = 0 Then
        If Turn = "Black" Then
            Response% = MsgBox("You have left your Emperor in Check! ", 0, "White")
        Else
            Board.PieceID.Caption = "White Emperor is in Check!": Notice = 1
        End If
    End If
End If
For AB = 1 To BoardSizeY
    For CD = 1 To BoardSizeX
        Camps(CD, AB) = 0
    Next CD
Next AB
Influence = OldInfluence: CompMove = OldCompMove: SeeMove = OldSeeMove

End Sub

Sub EmperorInfluence()

If Squares(InitFile, InitRank) > 0 Then
     Board.ForeColor = &H606060
Else
     Board.ForeColor = &HFFFFFF
End If
For EF = 2 To Pixels
    If Reverse = 0 Then
        If Squares(InitFile, InitRank) <> 0 Then
            If Squares(InitFile, InitRank) > 0 Then
                Board.Line (XStart + ((InitFile - 1) * Pixels) + EF - 2, 11 + ((InitRank - 1) * Pixels))-(XStart + ((InitFile - 1) * Pixels) + EF - 2, 11 + ((InitRank - 1) * Pixels) + PieceMask(Pieces(Abs(Squares(InitFile, InitRank))).Mask, EF) + 1)
            Else
                Board.Line (XStart + ((InitFile - 1) * Pixels) + (Pixels - EF), 9 + (InitRank * Pixels))-(XStart + ((InitFile - 1) * Pixels) + (Pixels - EF), 8 + (InitRank * Pixels) - (PieceMask(Pieces(Abs(Squares(InitFile, InitRank))).Mask, EF)))
            End If
        End If
    Else
        If Squares(InitFile, InitRank) <> 0 Then
            If Squares(InitFile, InitRank) > 0 Then
                Board.Line (XStart + ((BoardSizeX - InitFile) * Pixels + (Pixels - EF)), 8 + ((BoardSizeY - InitRank + 1) * Pixels) + 1)-(XStart + ((BoardSizeX - InitFile) * Pixels) + (Pixels - EF), 8 + ((BoardSizeY - InitRank + 1) * Pixels) - PieceMask(Pieces(Abs(Squares(InitFile, InitRank))).Mask, EF))
            Else
                Board.Line (XStart + ((BoardSizeX - InitFile) * Pixels) + EF - 2, 10 + ((BoardSizeY - InitRank) * Pixels) + 1)-(XStart + ((BoardSizeX - InitFile) * Pixels) + EF - 2, 12 + ((BoardSizeY - InitRank) * Pixels) + PieceMask(Pieces(Abs(Squares(InitFile, InitRank))).Mask, EF))
            End If
        End If
    End If
Next EF
Board.ForeColor = &H0&
Board.FillColor = &HFFFFFF

End Sub

Sub EndLionMove()
If LionPiece = I Then
    K = 1
    Do
        L = 1
        Do
            If Grafix(L, K) = I Then
                PieceName = Pieces(Abs(Squares(L, K))).Name
                Board.PieceID.Caption = PieceName
                File = L
                Rank = K
                Found = 1
            End If
            L = L + 1
        Loop Until L > BoardSizeX Or Found = 1
        K = K + 1
    Loop Until K > BoardSizeY Or Found = 1
    Found = 0
    Board.Frame.Visible = False
    LionPiece = -1
    LionBurn
    NextTurn
Else
    UnPromote
End If
End Sub

Sub EndSelect()
If MovePiece = 1 Then
    Board.Caption = Cap
    MovePiece = 0: Handicap = 0: Reduce = 0
    Board.Timer1.Enabled = True
    MoveCount = 0: TurnCount = 0
    If Turn = "White" Then MoveCount = 1
    Board.LastMove.Caption = ""
Else
    Handicap = 0: Reduce = 0: MovePiece = 0
    If Drop = 1 Then ResetHand
    If Turn = "White" Then MoveCount = 1
    Load AddPieces
End If
BugFix
End Sub

Sub EndSetup()

MovePiece = 0: Selection = 0: Reduce = 0: Handicap = 0: ExtraPiece = ""

End Sub

Sub EndTilde()
If Tilde = 1 Then
    ClearLegal
    Board.Refresh
    Tilde = 0
End If
End Sub

Sub FillSquare()
If Computer <> Turn And Computer <> "Both" And Level <> 0 And GameOver <> 1 Then
If Selection <> 0 Then
    If NewX > XStart And NewX < XStart + (BoardSizeX * Pixels) And NewY > 11 And NewY < 11 + (BoardSizeY * Pixels) Then
        GetSquare
        Squares(InitFile, InitRank) = Selection
        NewGraf = 0
        Do While Board.showpic(NewGraf).Visible = True
            NewGraf = NewGraf + 1
        Loop
        SetGrafix
    End If
    Reduce = 0: Handicap = 0: MovePiece = 0
    CheckAdd
Else
    Territory
End If
End If
End Sub

Sub FindEmperorMove()

BestCapture = 0: Vacant = 0
If Turn = "Black" Then
    KStart = BoardSizeY: JStart = BoardSizeX: KEnd = 1: JEnd = 1: Steps = -1
Else
    KStart = 1: JStart = 1: KEnd = BoardSizeY: JEnd = BoardSizeX: Steps = 1
End If
For K = KStart To KEnd Step Steps
    For J = JStart To JEnd Step Steps
        If Turn = "Black" And Squares(J, K) < 0 And Camps(J, K) <> 1 And Camps(J, K) <> 3 And WhiteEmperor <> 1 Then
           If Pieces(Abs(Squares(J, K))).Value > BestCapture Then
               BestCapture = Pieces(Abs(Squares(J, K))).Value: CaptureX = J: CaptureY = K
           End If
        End If
        If Turn = "White" And Squares(J, K) > 0 And Camps(J, K) < 2 And BlackEmperor <> 1 Then
           If Pieces(Abs(Squares(J, K))).Value > BestCapture Then
               BestCapture = Pieces(Abs(Squares(J, K))).Value: CaptureX = J: CaptureY = K
           End If
        End If
        If Turn = "Black" And Squares(J, K) = 0 And Camps(J, K) <> 1 And Camps(J, K) <> 3 And WhiteEmperor <> 1 And Vacant <> 1 Then
            VacantX = J: VacantY = K: Vacant = 1
        End If
        If Turn = "White" And Squares(J, K) = 0 And Camps(J, K) < 2 And BlackEmperor <> 1 And Vacant <> 1 Then
            VacantX = J: VacantY = K: Vacant = 1
        End If
        If Turn = "Black" And Squares(J, K) = 0 And Camps(J, K) = 2 And Vacant <> 1 Then
            VacantX = J: VacantY = K: Vacant = 1
        End If
        If Turn = "White" And Squares(J, K) = 0 And Camps(J, K) = 1 And Vacant <> 1 Then
            VacantX = J: VacantY = K: Vacant = 1
        End If
        Camps(J, K) = 0
    Next J
Next K
If Turn = "Black" Then InitFile = BlackEmpX: InitRank = BlackEmpY
If Turn = "White" Then InitFile = WhiteEmpX: InitRank = WhiteEmpY
If BestCapture > 0 Then
    SeeFile = CaptureX: SeeRank = CaptureY: AddEmperorMove
End If
SeeFile = VacantX: SeeRank = VacantY: AddEmperorMove
Influence = 0
End Sub

Sub FindInfluence()

Changed = 1
If LookMate = 1 Then
    Clearing(1).File = LastPieceX
    Clearing(1).Rank = LastPieceY
    File = LastPieceX: Rank = LastPieceY
    ClearInfo
End If
Clearing(Changed).File = CompFile
Clearing(Changed).Rank = CompRank
File = InitFile: Rank = InitRank
If InitFile <> 0 Then ClearInfo
If Squares(CompFile, CompRank) <> 0 Then
    File = CompFile: Rank = CompRank: CapturedPiece = 1: ClearInfo
Else
    For LL = 1 To Attacker(CompFile, CompRank)
        File = BanMap(CompFile, CompRank).Info(LL).File
        Rank = BanMap(CompFile, CompRank).Info(LL).Rank
        If File <> 0 And (InitFile <> File Or InitRank <> Rank) Then
            If Pieces(Abs(Squares(File, Rank))).Range <> 0 Then ClearInfo
        End If
    Next LL
End If
If ExtraCapture(AA).Piece <> 0 Then
    File = ExtraCapture(AA).File: Rank = ExtraCapture(AA).Rank:  ClearInfo
    For LL = 1 To Attacker(ExtraCapture(AA).File, ExtraCapture(AA).Rank)
        File = BanMap(ExtraCapture(AA).File, ExtraCapture(AA).Rank).Info(LL).File
        Rank = BanMap(ExtraCapture(AA).File, ExtraCapture(AA).Rank).Info(LL).Rank
        If Pieces(Abs(Squares(File, Rank))).Range <> 0 Then ClearInfo
    Next LL
End If
For LL = 1 To Attacker(InitFile, InitRank)
    File = BanMap(InitFile, InitRank).Info(LL).File
    Rank = BanMap(InitFile, InitRank).Info(LL).Rank
    If File <> 0 Then
        If Pieces(Abs(Squares(File, Rank))).Range <> 0 Then ClearInfo
    End If
Next LL

End Sub

Sub FireDemon()
Evaluate = 0
If SeeMove = 1 And Other <> 1 Then
    If (Influence = 0) Or (Squares(NewFile, NewRank) = 0 Or Sgn(Squares(InitFile, InitRank)) <> Sgn(Squares(NewFile, NewRank))) Then
    For K = NewRank - 1 To NewRank + 1
    For L = NewFile - 1 To NewFile + 1
        If L > 0 And L <= BoardSizeX And K > 0 And K <= BoardSizeY Then
            If ((Sgn(Squares(InitFile, InitRank)) <> Sgn(Squares(L, K))) And Squares(L, K) <> 0 And Legal(L, K) <> 1) Then
                If (K <> NewRank Or L <> NewFile) And Pieces(Abs(Squares(L, K))).special <> "F" Then
                    Board.FillColor = &HFFFF&
                    If Legal(L, K) < 1 Then SeeFile = L: SeeRank = K: LookMove
                End If
            End If
            If (Influence <> 0) And (Squares(L, K) = 0) Then
                SeeFile = L: SeeRank = K: LookMove
            End If
        End If
    Next L
    Next K
End If
End If
End Sub

Sub Flame()
W = 0
For K = Rank - 1 To Rank + 1
    For L = File - 1 To File + 1
        If L > 0 And L <= BoardSizeX And K > 0 And K <= BoardSizeY Then
            If (Sgn(Squares(File, Rank)) <> Sgn(Squares(L, K))) And Squares(L, K) <> 0 Then
                If Pieces(Abs(Squares(L, K))).Name <> "Fire Demon" Then
                    If Abs(Squares(L, K)) = 1 Or (Pieces(Abs(Squares(L, K))).Name = "Crown Prince" And King = 1) Then
                        File = L: Rank = K
                        CheckMate
                    End If
                    If Mate = 1 Then Exit Sub
                    If W = 0 Then CMove$ = CMove$ + Chr$(13) + Chr$(10) + "    x!" Else CMove$ = CMove$ + ","
                    If W = 3 Then CMove$ = CMove$ + Chr$(13) + Chr$(10) + "    "
                    CMove$ = CMove$ + Format$((BoardSizeX - L) + 1) + Chr$(K + 96)
                    Captures(TurnCount).number = Captures(TurnCount).number + 1
                    Captures(TurnCount).Positions(Captures(TurnCount).number) = (K * (BoardSizeX + 1)) + L
                    Captures(TurnCount).PieceNum(Captures(TurnCount).number) = Squares(L, K)
                    Squares(L, K) = 0
                    Board.showpic(Grafix(L, K)).Visible = False
                    Board.showpic(Grafix(L, K)).Move 0, 0
                    Grafix(L, K) = -1
                    W = W + 1
                End If
            End If
        End If
    Next L
Next K
End Sub

Sub FlashPiece()

If LastPieceX > -1 And LastPieceY > -1 Then
    If Grafix(LastPieceX, LastPieceY) > -1 Then
        CCC = 0: XA = 0: Blink = 0: PPP = 2
        Board.Timer2.Interval = 200
        Do
            If Blink / 2 = Int(Blink / 2) And PPP <> 2 Then
                Board.showpic(Grafix(LastPieceX, LastPieceY)).Visible = False: PPP = PPP + 1
                PPP = 2
                Board.Refresh
            End If
            If Blink / 2 <> Int(Blink / 2) And PPP <> 1 Then
                Board.showpic(Grafix(LastPieceX, LastPieceY)).Visible = True
                PPP = 1
                Board.Refresh
            End If
            DoEvents
        Loop Until (CCC = 1 Or Blink = 14)
        CCC = 0: XA = 0: Blink = 0: Board.Timer2.Interval = 0
        Board.showpic(Grafix(LastPieceX, LastPieceY)).Visible = True
    End If
End If

End Sub

Sub FormActing()
  
If Threat = "On" And SeeMove = 1 And GameOver <> 1 Then
    GetSquare
    ActingPieces
End If
End Sub

Sub FormDrop()

If MovePiece = 1 Then MoveFormDrop
If InitRank = 0 Then HeldDrop
If (NewX > XStart And NewX < XStart + (BoardSizeX * Pixels) And NewY > 11 And NewY < 11 + (BoardSizeY * Pixels)) Or CompMove = 1 Then
    GetSquare2
    If Legal(File, Rank) > 0 And RightClick <> 1 Then
        If LionPiece <> I Then
            Score(TurnCount).IDStart = Squares(InitFile, InitRank)
            Score(TurnCount).PosStart = (InitRank * (BoardSizeX + 1)) + InitFile
            CMove$ = CMove$ + Trim$(Pieces(Abs(Squares(InitFile, InitRank))).sname)
            CMove$ = CMove$ + Format$((BoardSizeX - InitFile) + 1) + Chr$(96 + InitRank)
            If (Computer = Turn Or Computer = "Both") And LionVictim.Piece <> 0 Then
                CMove$ = CMove$ + "x" + Format$((BoardSizeX - LionVictim.File) + 1) + Chr$(96 + LionVictim.Rank)
            End If
        End If
        CMove$ = CMove$ + "-" + Format$((BoardSizeX - File) + 1) + Chr$(Rank + 96)
        If Legal(File, Rank) = 1 Then LionPiece = -1
        Board.Frame.Visible = False
        Squares(File, Rank) = Squares(InitFile, InitRank)
        If Squares(File, Rank) = 1 Then BlackKingX = File: BlackKingY = Rank
        If Squares(File, Rank) = -1 Then WhiteKingX = File: WhiteKingY = Rank
        If Pieces(Abs(Squares(File, Rank))).Name = "Emperor" And Squares(File, Rank) > 0 Then BlackEmpX = File: BlackEmpY = Rank
        If Pieces(Abs(Squares(File, Rank))).Name = "Emperor" And Squares(File, Rank) < 0 Then WhiteEmpX = File: WhiteEmpY = Rank
        Score(TurnCount).PosEnd = (Rank * (BoardSizeX + 1)) + File
        Score(TurnCount).IDEnd = Squares(File, Rank)
        If LionVictim.Piece <> 0 Then
            Captures(TurnCount).number = Captures(TurnCount).number + 1
            Captures(TurnCount).Positions(Captures(TurnCount).number) = (LionVictim.Rank * (BoardSizeX + 1)) + LionVictim.File
            Captures(TurnCount).PieceNum(Captures(TurnCount).number) = Squares(LionVictim.File, LionVictim.Rank)
            Taken = 1
        End If
        Grafix(File, Rank) = I
        If InitFile <> File Or InitRank <> Rank Then Grafix(InitFile, InitRank) = -1
        If InitFile <> File Or InitRank <> Rank Then Squares(InitFile, InitRank) = 0
        If LionVictim.Piece <> 0 Then
            Squares(LionVictim.File, LionVictim.Rank) = 0
            Board.showpic(Grafix(LionVictim.File, LionVictim.Rank)).Visible = False
            Board.showpic(Grafix(LionVictim.File, LionVictim.Rank)).Move 0, 0
            Grafix(LionVictim.File, LionVictim.Rank) = -1
        End If
        If Legal(File, Rank) = 3 Then
            Score(TurnCount).IDEnd = 0
            Grafix(File, Rank) = -1
            Board.showpic(I).Visible = False
            Board.showpic(I).Move 0, 0
            Squares(File, Rank) = 0
            LionPiece = -1
        Else
            If Reverse = 0 Then
                Board.showpic(I).Move XStart + ((File - 1) * Pixels), 11 + ((Rank - 1) * Pixels)
            Else
                Board.showpic(I).Move XStart + ((BoardSizeX - File) * Pixels), 11 + ((BoardSizeY - Rank) * Pixels)
            End If
        End If
        If Demon = 1 Then Flame
        If Mate <> 1 Then
             If Legal(File, Rank) = 3 Then CMove$ = CMove$ + "*"
             If Legal(File, Rank) = 6 Then Teach = 3
             If Legal(File, Rank) = 2 Then Teach = 2 Else Teach = 1
             If Legal(L, K) = 2 Or Legal(L, K) = 6 Then
                 DoubleMove
             Else
                 LastPieceX = File: LastPieceY = Rank
                 If CompMove <> 1 Then NextTurn
             End If
         End If
    End If
End If
ClearLegal
If Mate = 1 Then
    GameOver = 1
    Response% = MsgBox("        Checkmate!          ", 0, Turn + " Wins!"): NextTurn
End If
End Sub

Sub GetSquare()
If Reverse = 0 Then
    InitFile = Int((NewX - XStart) / Pixels) + 1
    InitRank = Int((NewY - 11) / Pixels) + 1
Else
    InitFile = Int((BoardSizeX * Pixels - (NewX - XStart)) / Pixels) + 1
    InitRank = Int((BoardSizeY * Pixels - (NewY - 11)) / Pixels) + 1
End If
If InitRank < 1 Or InitRank > BoardSizeY Or InitFile < 1 Or InitFile > BoardSizeX Then
    InitRank = 0: InitFile = 0
End If
End Sub

Sub GetSquare2()

If CompMove <> 1 And DropTest <> 1 Then
    If Reverse = 0 Then
        File = Int((NewX - XStart) / Pixels) + 1
        Rank = Int((NewY - 11) / Pixels) + 1
    Else
        File = Int((BoardSizeX * Pixels - (NewX - XStart)) / Pixels) + 1
        Rank = Int((BoardSizeY * Pixels - (NewY - 11)) / Pixels) + 1
    End If
End If
End Sub

Sub HeldDown()

If Computer <> Turn And Computer <> "Both" And Level <> 0 And GameOver <> 1 Then
Notice = 0
Board.PieceID.ForeColor = &HFF0000
If Selection <> 0 Or MovePiece = 1 Then
    AddHand2
Else
    If Reduce = 1 Then
        InHand(I) = InHand(I) - 1
        If InHand(I) < 2 Then Board.Held(I).Caption = "" Else Board.Held(I).Caption = InHand(I)
        If InHand(I) < 1 Then Board.HandPic(I).Visible = False
    Else
        Board.Caption = Cap
        Board.PieceID.Caption = Pieces(Abs(CapRef(I))).Name
        If (I > Capture And Turn = "White" And Reverse = 0) Or (I <= Capture And Turn = "Black" And Reverse = 0) Or (I > Capture And Turn = "Black" And Reverse = 1) Or (I <= Capture And Turn = "White" And Reverse = 1) Then
            Board.HandPic(I).Drag 1
            HeldValid
        Else
            Board.FillStyle = 1: Other = 1
            Board.ForeColor = &HC00000
            HeldValid
            Board.ForeColor = &H0
            Board.FillStyle = 0: Other = 0
        End If
    End If
End If
End If
End Sub

Sub HeldDrop()

If (NewX > XStart And NewX < XStart + (BoardSizeX * Pixels) And NewY > 11 And NewY < 11 + (BoardSizeY * Pixels)) Or DropTest = 1 Then
    GetSquare2
    If Legal(File, Rank) = 1 Then
        Squares(File, Rank) = CapRef(I)
        NewGraf = 0
        Do While Board.showpic(NewGraf).Visible = True
            NewGraf = NewGraf + 1
        Loop
        Score(TurnCount).IDStart = Squares(File, Rank)
        Score(TurnCount).IDEnd = Squares(File, Rank)
        Score(TurnCount).PosStart = 0
        Score(TurnCount).PosEnd = (Rank * (BoardSizeX + 1)) + File
        CMove$ = Trim$(Pieces(Abs(Squares(File, Rank))).sname)
        CMove$ = CMove$ + "*" + Format$((BoardSizeX - File) + 1) + Chr$(Rank + 96)
        Grafix(File, Rank) = NewGraf
        Board.showpic(NewGraf) = Board.HandPic(I)
        If Reverse = 0 Then
            Board.showpic(NewGraf).Move XStart + (File - 1) * Pixels, 11 + (Rank - 1) * Pixels
        Else
            Board.showpic(NewGraf).Move XStart + (BoardSizeX - File) * Pixels, 11 + (BoardSizeY - Rank) * Pixels
        End If
        Board.showpic(NewGraf).Visible = True
        InHand(I) = InHand(I) - 1
        If InHand(I) < 1 Then Board.HandPic(I).Visible = False
        If InHand(I) < 2 Then Board.Held(I).Caption = "" Else Board.Held(I).Caption = InHand(I)
        If Choice = "Micro" Then MicroDrop
        InitRank = 0: InitFile = 0
        Dropped = 1
        LastPieceX = File: LastPieceY = Rank
        If CompMove <> 1 Then NextTurn
    End If
End If
ClearLegal
End Sub

Sub HeldProm()

If Computer <> Turn And Computer <> "Both" And Level <> 0 And GameOver <> 1 Then
    Board.PieceID.Caption = ""
    Board.PieceID.ForeColor = &H8000&
    If Pieces(Abs(CapRef(I))).Promotes > 0 And Pieces(Abs(CapRef(I))).Name <> "Killer Whale" Then PromName = Pieces(Abs(Pieces(Abs(CapRef(I))).Promotes)).Name Else PromName = "None"
    Board.PieceID.Caption = "Promotes to " + PromName
End If
End Sub

Sub HeldShow()
If SeeMove = 1 Or CompMove = 1 Then
    Board.FillColor = &HFFFFFF
    For K = 1 To BoardSizeY
        For L = 1 To BoardSizeX
            If Legal(L, K) = 1 Then SeeFile = L: SeeRank = K: LookMove
        Next L
    Next K
End If
If Evaluate <> 1 And DropTest <> 1 Then InitRank = 0
End Sub

Sub HeldValid()
For K = 1 To BoardSizeY
    For L = 1 To BoardSizeX
        If Squares(L, K) = 0 Then Legal(L, K) = 1
        If Pieces(Abs(CapRef(I))).special = "1" Then
            If CapRef(I) > 0 And K = 1 Then Legal(L, K) = 0
            If CapRef(I) < 0 And K = BoardSizeY Then Legal(L, K) = 0
        End If
        If Pieces(Abs(CapRef(I))).special = "2" Then
            If CapRef(I) > 0 And K < 3 Then Legal(L, K) = 0
            If CapRef(I) < 0 And K > BoardSizeY - 2 Then Legal(L, K) = 0
        End If
    Next L
Next K
If (Choice <> "Micro") And (Pieces(Abs(CapRef(I))).Name = "Pawn" Or Pieces(Abs(CapRef(I))).Name = "Sparrow Pawn") Then
    For N = 1 To BoardSizeY
        For P = 1 To BoardSizeX
            If Squares(P, N) <> 0 Then
                If (Pieces(Abs(Squares(P, N))).Name = "Pawn" Or Pieces(Abs(Squares(P, N))).Name = "Sparrow Pawn") And Sgn(Squares(P, N)) = Sgn(CapRef(I)) Then
                    For X = 1 To BoardSizeY
                        Legal(P, X) = 0
                    Next X
                End If
            End If
        Next P
    Next N
End If
If Choice = "Tori" And Pieces(Abs(CapRef(I))).Name = "Swallow" Then
    For N = 1 To BoardSizeX
        C = 0
        For P = 1 To BoardSizeY
            If Squares(N, P) <> 0 Then
                If Pieces(Abs(Squares(N, P))).Name = "Swallow" And Sgn(Squares(N, P)) = Sgn(CapRef(I)) Then
                    C = C + 1
                    If C = 2 Then
                        For X = 1 To BoardSizeY
                            Legal(N, X) = 0
                        Next X
                    End If
                End If
            End If
        Next P
    Next N
End If
If Choice = "Whale" And Pieces(Abs(CapRef(I))).Name = "Dolphin" Then
    For N = 1 To BoardSizeX
        C = 0
        For P = 1 To BoardSizeY
            If Squares(N, P) <> 0 Then
                If Pieces(Abs(Squares(N, P))).Name = "Dolphin" And Sgn(Squares(N, P)) = Sgn(CapRef(I)) Then
                    C = C + 1
                    If C = 2 Then
                        For X = 1 To BoardSizeY
                            Legal(N, X) = 0
                        Next X
                    End If
                End If
            End If
        Next P
    Next N
End If
If CompMove <> 1 Then AskMate
If Dropping <> 1 Then HeldShow
End Sub

Sub HookMove()
OldLast = Last: OldFile = NewFile: OldRank = NewRank
While NewFile - RankInc > 0 And NewFile - RankInc <= BoardSizeX And NewRank + FileInc > 0 And NewRank + FileInc <= BoardSizeY And Last = 0
    NewFile = NewFile - RankInc
    NewRank = NewRank + FileInc
    ShowMove
Wend
NewFile = OldFile: NewRank = OldRank: Last = 0
While NewFile + RankInc > 0 And NewFile + RankInc <= BoardSizeX And NewRank - FileInc > 0 And NewRank - FileInc <= BoardSizeY And Last = 0
    NewFile = NewFile + RankInc
    NewRank = NewRank - FileInc
    ShowMove
Wend
NewFile = OldFile: NewRank = OldRank: Last = OldLast
End Sub

Sub Igui()
For K = InitRank - 1 To InitRank + 1
    For L = InitFile - 1 To InitFile + 1
        If K > 0 And K <= BoardSizeY And L > 0 And L <= BoardSizeX Then
            If Sgn(Squares(InitFile, InitRank)) <> Sgn(Squares(L, K)) Or (Squares(L, K) = 0 And Influence > 0) Then
                Board.FillColor = &H8000&
                If SeeMove = 1 Then SeeFile = L: SeeRank = K: LookMove
                Legal(L, K) = 4
            End If
        End If
    Next L
Next K
End Sub

Sub Jumping()
NewFile = InitFile + (FileInc * 2): NewRank = InitRank + (RankInc * 2)
If NewFile > 0 And NewFile <= BoardSizeX And NewRank > 0 And NewRank <= BoardSizeY Then ShowMove
End Sub

Sub KingSafety()
    
' King Safety \ Attacks

If Choice <> "Micro" And Choice <> "Mini" And Choice <> "Judkin" And Choice <> "Yari" And Choice <> "Tori" And Choice <> "Whale" Then
    If CompLegal(AA).EndPiece = 1 Then
        If Abs(InitFile - ((BoardSizeX / 2) + 0.5)) < Abs(CompFile - ((BoardSizeX / 2) + 0.5)) Then KingTally(AA) = KingTally(AA) + 3
        KingTally(AA) = KingTally(AA) - (BoardSizeY - CompRank)
    End If
    If CompLegal(AA).EndPiece = -1 Then
        If Abs(((BoardSizeX / 2) + 0.5) - InitFile) < Abs(((BoardSizeX / 2) + 0.5) - CompFile) Then KingTally(AA) = KingTally(AA) + 3
        KingTally(AA) = KingTally(AA) - (CompRank - 1)
    End If
    If Turn = "Black" And Pieces(Abs(CompLegal(AA).EndPiece)).Name = "Gold" And Abs(CompFile - BlackKingX) > 1 And Abs(CompRank - BlackKingY) > 1 And (Abs(CompFile - BlackKingX) > Abs(InitFile - BlackKingX) Or Abs(CompRank - BlackKingY) > Abs(InitRank - BlackKingY)) Then KingTally(AA) = KingTally(AA) - 2
    If Turn = "White" And Pieces(Abs(CompLegal(AA).EndPiece)).Name = "Gold" And Abs(CompFile - WhiteKingX) > 1 And Abs(CompRank - WhiteKingY) > 1 And (Abs(CompFile - WhiteKingX) > Abs(InitFile - WhiteKingX) Or Abs(CompRank - WhiteKingY) > Abs(InitRank - WhiteKingY)) Then KingTally(AA) = KingTally(AA) - 2
End If
If Turn = "Black" And CompRank <= PromDotY Then KingTally(AA) = KingTally(AA) + 3
If Turn = "White" And CompRank > BoardSizeY - PromDotY Then KingTally(AA) = KingTally(AA) + 3
If BoardSizeY > 11 Then
    If Turn = "Black" And Pieces(Abs(CompLegal(AA).EndPiece)).Range <> 1 And InitRank > CompRank Then KingTally(AA) = KingTally(AA) + 3
    If Turn = "White" And Pieces(Abs(CompLegal(AA).EndPiece)).Range <> 1 And InitRank < CompRank Then KingTally(AA) = KingTally(AA) + 3
    If Turn = "Black" And Pieces(Abs(CompLegal(AA).EndPiece)).Range = 1 And InitRank < CompRank Then KingTally(AA) = KingTally(AA) + 2
    If Turn = "White" And Pieces(Abs(CompLegal(AA).EndPiece)).Range = 1 And InitRank > CompRank Then KingTally(AA) = KingTally(AA) + 2
End If
If Turn = "Black" And InitRank < BoardSizeY * 0.35 Then
    If Abs(InitFile - WhiteKingX) > Abs(CompFile - WhiteKingX) Or Abs(InitRank - WhiteKingY) > Abs(CompRank - WhiteKingY) Then KingTally(AA) = KingTally(AA) + 5
End If
If Turn = "White" And InitRank > BoardSizeY * 0.65 Then
    If Abs(InitFile - BlackKingX) > Abs(CompFile - BlackKingX) Or Abs(InitRank - BlackKingY) > Abs(CompRank - BlackKingY) Then KingTally(AA) = KingTally(AA) + 5
End If

End Sub

Sub KnightJump()
If Abs(RankInc) = 1 Then
    NewFile = InitFile + 1: NewRank = InitRank + (RankInc * 2)
    If NewFile <= BoardSizeX And NewRank > 0 And NewRank <= BoardSizeY Then ShowMove
    NewFile = InitFile - 1
    If NewFile > 0 And NewRank > 0 And NewRank <= BoardSizeY Then ShowMove
End If
If Abs(FileInc) = 1 Then
    NewRank = InitRank + 1: NewFile = InitFile + (FileInc * 2)
    If NewRank <= BoardSizeY And NewFile > 0 And NewFile <= BoardSizeX Then ShowMove
    NewRank = InitRank - 1
    If NewRank > 0 And NewFile > 0 And NewFile <= BoardSizeX Then ShowMove
End If
End Sub

Sub Lion()
If Teach = 1 Then
    Lion2
Else
    For Y = InitRank - 2 To InitRank + 2
        For X = InitFile - 2 To InitFile + 2
            If X > 0 And X <= BoardSizeX And Y > 0 And Y <= BoardSizeY Then
                If Squares(X, Y) = 0 Or Sgn(Squares(X, Y)) <> Sgn(Squares(InitFile, InitRank)) Or (Influence > 0 And (Y <> InitRank Or X <> InitFile)) Then
                    If Abs(Y - InitRank) <= 1 And Abs(X - InitFile) <= 1 Then
                        Board.FillColor = &HFF0000
                        NewRank = Y: NewFile = X
                        If Choice = "Tenjiku" Then CheckBurn
                        If LegalMoves > 0 And Squares(X, Y) <> 0 And Pieces(Abs(Squares(InitFile, InitRank))).Name <> "Teaching King" Then
                            If Evaluate = 0 And CompMove = 1 And Influence <> 1 Then CompLion
                            Legal(X, Y) = 1
                        Else
                            Legal(X, Y) = 2
                        End If
                    Else
                        Legal(X, Y) = 1
                        NewRank = Y: NewFile = X
                        If Choice = "Chu" And Squares(X, Y) <> 0 And ChuLionTest <> 1 Then
                            If Pieces(Abs(Squares(X, Y))).Name = "Lion" Then ChuLion
                        End If
                        Board.FillColor = &HFFFF00
                        If Choice = "Tenjiku" Then CheckBurn
                    End If
                    If SeeMove = 1 And ProtectLion <> 1 And CompLionTest <> 1 And Legal(X, Y) > 0 Then SeeFile = X: SeeRank = Y: LookMove
                    ProtectLion = 0: CompLionTest = 0
                End If
            End If
        Next X
    Next Y
End If
End Sub

Sub Lion2()
For Y = InitRank - 1 To InitRank + 1
    For X = InitFile - 1 To InitFile + 1
        If X > 0 And X <= BoardSizeX And Y > 0 And Y <= BoardSizeY Then
            If Squares(X, Y) = 0 Or Sgn(Squares(X, Y)) <> Sgn(Squares(InitFile, InitRank)) Or Influence = 2 Then
                Legal(X, Y) = 1
                Board.FillColor = &HFFFF00
                If SeeMove = 1 Then SeeFile = X: SeeRank = Y: LookMove
                NewFile = X: NewRank = Y
                If Choice = "Tenjiku" Then CheckBurn
            End If
        End If
    Next X
Next Y
End Sub

Sub LionBurn()

For K = Rank - 1 To Rank + 1
    For L = File - 1 To File + 1
        If LionTest <> 1 And L > 0 And L <= BoardSizeX And K > 0 And K <= BoardSizeY Then
            If (K <> Rank Or L <> File) And Squares(L, K) <> 0 Then
                If Pieces(Abs(Squares(L, K))).special = "F" And Sgn(Squares(File, Rank)) <> Sgn(Squares(L, K)) Then LionBurn2
            End If
        End If
    Next L
Next K
LionTest = 0
End Sub

Sub LionBurn2()

Score(TurnCount).IDEnd = 0
CMove$ = CMove$ + "*"
Grafix(File, Rank) = -1
Board.showpic(I).Visible = False
Board.showpic(I).Move 0, 0
Squares(File, Rank) = 0
LionTest = 1
End Sub

Sub LionIgui()
        
If BoardSizeY > 11 Then
    MMM = 0
    For K = 1 To BoardSizeY
        For L = 1 To BoardSizeX
            If Grafix(L, K) = I Then File = L: Rank = K: MMM = 1: Exit For
        Next L
        If MMM = 1 Then Exit For
    Next K
    If MMM = 1 And ((Turn = "Black" And Squares(File, Rank) > 0) Or (Turn = "White" And Squares(File, Rank) < 0)) Then
        If Pieces(Abs(Squares(File, Rank))).special = "L" Or Pieces(Abs(Squares(File, Rank))).Name = "Horned Falcon" Or Pieces(Abs(Squares(File, Rank))).Name = "Soaring Eagle" Or (Pieces(Abs(Squares(File, Rank))).Name = "Teaching King" And TeachVer = 2) Then
            InitFile = File: InitRank = Rank
            Score(TurnCount).IDStart = Squares(File, Rank)
            Score(TurnCount).IDEnd = Squares(File, Rank)
            Score(TurnCount).PosStart = (InitRank * (BoardSizeX + 1)) + InitFile
            Score(TurnCount).PosEnd = (InitRank * (BoardSizeX + 1)) + InitFile
            CMove$ = CMove$ + Trim$(Pieces(Abs(Squares(InitFile, InitRank))).sname) + "!"
            LastPieceX = File: LastPieceY = Rank
            Ligui = 1
            ShortScore(TurnCount + 1) = CMove$
            NextTurn
        End If
    End If
End If
End Sub

Sub LionPower()
For K = 1 To 2
    C = InitFile: D = InitRank
    NewFile = InitFile + (FileInc * K): NewRank = InitRank + (RankInc * K)
    If NewFile > 0 And NewFile <= BoardSizeX And NewRank > 0 And NewRank <= BoardSizeY Then
        If Squares(NewFile, NewRank) = 0 Or Sgn(Squares(InitFile, InitRank)) <> Sgn(Squares(NewFile, NewRank)) Or (Influence > 0 And (NewFile <> InitFile Or NewRank <> InitRank)) Then
            If K = 1 Then
                Board.FillColor = &HFF0000
                If Choice = "Tenjiku" Then CheckBurn
                If LegalMoves > 0 And Squares(NewFile, NewRank) <> 0 Then
                    If CompMove = 1 And Evaluate = 0 And Influence <> 1 Then CompLionPower
                    Legal(NewFile, NewRank) = 1
                Else
                    Legal(NewFile, NewRank) = 2
                End If
            Else
                Board.FillColor = &HFFFF00
                Legal(NewFile, NewRank) = 1
                If Choice = "Tenjiku" Then CheckBurn
            End If
            If SeeMove = 1 And CompLionTest <> 1 And Legal(NewFile, NewRank) <> 0 Then SeeFile = NewFile: SeeRank = NewRank: LookMove
            CompLionTest = 0
        End If
    End If
Next K
End Sub

Sub LionPower2()
Legal(C, D) = 1
Board.FillColor = &HFFFF00
SeeFile = C: SeeRank = D: LookMove
X = InitFile + (InitFile - C)
Y = InitRank + (InitRank - D)
If X > 0 And X <= BoardSizeX And Y > 0 And Y <= BoardSizeY Then
    If Squares(X, Y) = 0 Or Sgn(Squares(InitFile, InitRank)) <> Sgn(Squares(X, Y)) Or (Influence = 2 And (NewFile <> InitFile Or NewRank <> InitRank)) Then
        Legal(X, Y) = 1
        If SeeMove = 1 Then SeeFile = X: SeeRank = Y: LookMove
        NewFile = X: NewRank = Y
        If Choice = "Tenjiku" Then CheckBurn
    End If
End If
End Sub

Sub LoadGame()
On Error Resume Next
Board.CMSave.DialogTitle = "Load Game"
Board.CMSave.Flags = &H1000&
Board.CMSave.Action = 1
If Err = 32755 Then Exit Sub
Loaded$ = Board.CMSave.FileName
Loading = 1
OldChoice = Choice
Open Loaded$ For Input As #2
Input #2, Choice
If Choice = "Tai" And Display < 800 Then
    TooSmall
    Choice = OldChoice
    Loading = 0
    Close #2
Else
    Unload PieceHelp
    Unload RulesHelp
    Board.MousePointer = 11
    If Choice = OldChoice Then Unload Board
    StartUp
    Input #2, SaveTitle$
    If SaveTitle$ <> "" Then
        Cap = SaveTitle$
        Board.Caption = Cap
    End If
    Input #2, Computer
    Input #2, Level
    Input #2, GameOver
    Input #2, Threat
    Close #2
    EndTurn = TurnCount
    ConfigLoad
    Loading = 0
    Board.MnuHandicap.Enabled = False
    If GameOver <> 1 Then ConvertScore
    If Asc(Score(TurnCount).Caption) > 47 And Asc(Score(TurnCount).Caption) < 58 Then
        Board.LastMove.Caption = Score(TurnCount).Caption
    Else
        Board.LastMove.Caption = Format$(MoveCount) + ". " + Score(TurnCount).Caption
    End If
    If TurnCount > 0 Then
        Location = Score(TurnCount - 1).PosEnd
        If Location > 0 Then
            Rank = Int(Location / (BoardSizeX + 1))
            File = Location - (Rank * (BoardSizeX + 1))
        End If
        LastPieceX = File: LastPieceY = Rank
    Else
        LastPieceX = -1: LastPieceY = -1
    End If
End If
End Sub

Sub LoadGame2()
On Error Resume Next
Start.CMSave.DialogTitle = "Load Game"
Start.CMSave.Flags = &H1000&
Start.CMSave.Action = 1
If Err = 32755 Then Exit Sub
Loaded$ = Start.CMSave.FileName
Start.MousePointer = 11
Loading = 1
OldChoice = Choice
Open Loaded$ For Input As #2
Input #2, Choice
If Choice = "Tai" And Display < 800 Then
    TooSmall
    Choice = OldChoice
    Loading = 0
    Close #2
Else
Unload PieceHelp
Unload RulesHelp
Unload Board
StartUp
Input #2, SaveTitle$
If SaveTitle$ <> "" Then Board.Caption = SaveTitle$
Input #2, Computer
Input #2, Level
Input #2, GameOver
Input #2, Threat
Close #2
Start.Hide
Start.MousePointer = 0
ConfigLoad
Loading = 0
EndTurn = TurnCount
Board.MnuHandicap.Enabled = False
If GameOver <> 1 Then ConvertScore
If Asc(Score(TurnCount).Caption) > 47 And Asc(Score(TurnCount).Caption) < 58 Then
    Board.LastMove.Caption = Score(TurnCount).Caption
Else
    Board.LastMove.Caption = Format$(MoveCount) + ". " + Score(TurnCount).Caption
End If
If TurnCount > 0 Then
    Location = Score(TurnCount - 1).PosEnd
    If Location > 0 Then
        Rank = Int(Location / (BoardSizeX + 1))
        File = Location - (Rank * (BoardSizeX + 1))
    End If
    LastPieceX = File: LastPieceY = Rank
Else
    LastPieceX = -1: LastPieceY = -1
End If
End If
End Sub

Sub LookAhead()

If Turn = "White" Then Turn = "Black" Else Turn = "White"
RealLevel = Level: Level = 0
For YYY = 1 To BoardSizeY
    For XXX = 1 To BoardSizeX
        TestBoard(XXX, YYY) = Comp(XXX, YYY)
    Next XXX
Next YYY
If Drop = 1 Then
    For DDD = 1 To Capture * 2
        OldHand(DDD) = InHand(DDD)
    Next DDD
End If
For Depth = 1 To TestDepth
    If MoveList(Depth).StartFile <> 0 Then Comp(MoveList(Depth).StartFile, MoveList(Depth).StartRank) = 0
    Comp(MoveList(Depth).EndFile, MoveList(Depth).EndRank) = MoveList(Depth).EndPiece
    If MoveList(Depth).StartFile = 0 Then
        For DDD = 1 To Capture * 2
            If MoveList(Depth).EndPiece = CapRef(DDD) Then InHand(DDD) = InHand(DDD) - 1
        Next DDD
    End If
    TestAhead
    FinalTally(Depth) = BestTally(0) - OldKingTally(Depth)
    For YYY = 1 To BoardSizeY
        For XXX = 1 To BoardSizeX
            Comp(XXX, YYY) = TestBoard(XXX, YYY)
        Next XXX
    Next YYY
    If Drop = 1 Then
        For DDD = 1 To Capture * 2
            InHand(DDD) = OldHand(DDD)
        Next DDD
    End If
Next Depth
Level = RealLevel: BestMove = TestDepth: BestScore = FinalTally(TestDepth)
If Turn = "White" Then Turn = "Black" Else Turn = "White"
For ZZZZ = 1 To TestDepth - 1
    If FinalTally(ZZZZ) < BestScore Then
        BestMove = ZZZZ
        BestScore = FinalTally(ZZZZ)
    End If
Next ZZZZ
CompLegal(BestMove).StartFile = MoveList(BestMove).StartFile
CompLegal(BestMove).StartRank = MoveList(BestMove).StartRank
CompLegal(BestMove).StartPiece = MoveList(BestMove).StartPiece
CompLegal(BestMove).EndFile = MoveList(BestMove).EndFile
CompLegal(BestMove).EndRank = MoveList(BestMove).EndRank
CompLegal(BestMove).EndPiece = MoveList(BestMove).EndPiece
If Choice = "Dai" Or Choice = "Chu" Or Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tenjiku" Or Choice = "Tai" Then
    LionVictim.Piece = ECapture(BestMove).Piece
    LionVictim.File = ECapture(BestMove).File
    LionVictim.Rank = ECapture(BestMove).Rank
End If

End Sub

Sub LookCheck()

If Turn = "White" And BlackKing = 0 Then
    OriginalPiece = Squares(BlackKingX, BlackKingY)
    OriginalFile = BlackKingX: OriginalRank = BlackKingY
Else
    If Turn = "Black" And WhiteKing = 0 Then
        OriginalPiece = Squares(WhiteKingX, WhiteKingY)
        OriginalFile = WhiteKingX: OriginalRank = WhiteKingY
    End If
End If
Influence = 0
CheckTest = 1
CheckLooked = 0
LookCheck2
CheckTest = 0
If GameOver = 1 Or Checked > 0 Then Exit Sub
For GHH = 1 To BoardSizeY
    For EFF = 1 To BoardSizeX
        If Squares(EFF, GHH) <> 0 Then
            If Abs(Squares(EFF, GHH)) = 1 Or Pieces(Abs(Squares(EFF, GHH))).Name = "Emperor" Or Pieces(Abs(Squares(EFF, GHH))).Name = "Crown Prince" Or Pieces(Abs(Squares(EFF, GHH))).Name = "Prince" Then
                OriginalPiece = Squares(EFF, GHH)
                OriginalFile = EFF: OriginalRank = GHH
                Influence = 0
                CheckTest = 1
                CheckLooked = 0
                LookCheck2
                CheckTest = 0
                If GameOver = 1 Or Checked > 0 Then Exit Sub
            End If
        End If
    Next EFF
Next GHH
CheckTest = 0
End Sub

Sub LookCheck2()

For ABB = 1 To BoardSizeY
    For CDD = 1 To BoardSizeX
        If Squares(CDD, ABB) <> 0 Then
            If Sgn(OriginalPiece) <> Sgn(Squares(CDD, ABB)) And Pieces(Abs(Squares(CDD, ABB))).Name <> "Emperor" Then
                InitFile = CDD: InitRank = ABB
                Validate
                If GameOver = 1 Or Checked > 0 Then Influence = 0: Exit Sub
            End If
        End If
    Next CDD
Next ABB
Influence = 0

End Sub

Sub LookComp()

Attacker(SeeFile, SeeRank) = Attacker(SeeFile, SeeRank) + 1
BanMap(SeeFile, SeeRank).Info(Attacker(SeeFile, SeeRank)).File = InitFile
BanMap(SeeFile, SeeRank).Info(Attacker(SeeFile, SeeRank)).Rank = InitRank
BanMap(SeeFile, SeeRank).Info(Attacker(SeeFile, SeeRank)).Piece = Squares(InitFile, InitRank)
If Squares(InitFile, InitRank) < 0 Then
    BanMap(SeeFile, SeeRank).WhiteNum = BanMap(SeeFile, SeeRank).WhiteNum + 1
Else
    BanMap(SeeFile, SeeRank).BlackNum = BanMap(SeeFile, SeeRank).BlackNum + 1
End If
DoEvents
If FirstTime = 1 Then LookComp2
End Sub

Sub LookComp2()

OldAttack(SeeFile, SeeRank) = Attacker(SeeFile, SeeRank)
BackMap(SeeFile, SeeRank).Info(Attacker(SeeFile, SeeRank)).File = InitFile
BackMap(SeeFile, SeeRank).Info(Attacker(SeeFile, SeeRank)).Rank = InitRank
BackMap(SeeFile, SeeRank).Info(Attacker(SeeFile, SeeRank)).Piece = Squares(InitFile, InitRank)
If Squares(InitFile, InitRank) < 0 Then
    BackMap(SeeFile, SeeRank).WhiteNum = BanMap(SeeFile, SeeRank).WhiteNum
Else
    BackMap(SeeFile, SeeRank).BlackNum = BanMap(SeeFile, SeeRank).BlackNum
End If
End Sub

Sub LookForMate()
LookMate = 1
OldComputer = Computer
Computer = Turn2: OldTurn = Turn: Turn = Turn2
RealLevel = Level: Level = 0
CompMain
Level = RealLevel
LookMate = 0: LegalMoves = 0: Turn = OldTurn
Computer = OldComputer
End Sub

Sub LookMove()

If ChuLionTest = 1 Then
    If SeeFile = OldNewFile And SeeRank = OldNewRank Then ProtectLion = 1: Exit Sub
Else
If Evaluate = 1 Then
    LookComp
Else
If CompMove = 1 And Influence <> 2 And Evaluate = 0 Then
     AddLegalMove
Else
If (Influence < 1 And CheckTest <> 1) Then
    If Reverse = 0 Then
        Board.Circle (XStart + ((SeeFile - 1) * Pixels) + (Pixels / 2), 11 + ((SeeRank - 1) * Pixels) + (Pixels / 2)), Pixels / 4
    Else
        Board.Circle (XStart + ((BoardSizeX - SeeFile) * Pixels) + (Pixels / 2), 11 + ((BoardSizeY - SeeRank) * Pixels) + (Pixels / 2)), Pixels / 4
    End If
Else
    If Influence = 2 Then
        If Legal(SeeFile, SeeRank) > 0 Then
            If Squares(InitFile, InitRank) < 0 Then
                If (Camps(SeeFile, SeeRank) <> 2 And Camps(SeeFile, SeeRank) <> 3) Then Camps(SeeFile, SeeRank) = 1 Else Camps(SeeFile, SeeRank) = 3
            Else
                If (Camps(SeeFile, SeeRank) <> 1 And Camps(SeeFile, SeeRank) <> 3) Then Camps(SeeFile, SeeRank) = 2 Else Camps(SeeFile, SeeRank) = 3
            End If
        End If
    Else
        If OriginalFile = SeeFile And OriginalRank = SeeRank Then
            If CheckTest = 1 And CheckLooked = 0 Then
                Response% = 0
                If OriginalPiece > 0 And Turn = "White" And Computer <> "Black" And Computer <> "Both" And ((BlackKing = 0 And BlackPrince > 0) Or (Choice = "Tenjiku" Or Choice = "Maka" Or Choice = "Tai")) Then Response% = MsgBox("You have left your " + Pieces(Abs(OriginalPiece)).Name + " in Check! ", 0, "Black"): Response% = 6
                If OriginalPiece < 0 And Turn = "Black" And Computer <> "White" And Computer <> "Both" And ((WhiteKing = 0 And WhitePrince > 0) Or (Choice = "Tenjiku" Or Choice = "Maka" Or Choice = "Tai")) Then Response% = MsgBox("You have left your " + Pieces(Abs(OriginalPiece)).Name + " in Check! ", 0, "White"): Response% = 6
                If Choice <> "Tenjiku" And Choice <> "Maka" And Choice <> "Tai" Then
                    If OriginalPiece > 0 And Turn = "White" And Computer <> "Black" And Computer <> "Both" And (BlackKing = 1 Or BlackPrince = 0) Then Response% = MsgBox("You can't leave your " + Pieces(Abs(OriginalPiece)).Name + " in Check! ", 0, "Black"): Response% = 7
                    If OriginalPiece < 0 And Turn = "Black" And Computer <> "White" And Computer <> "Both" And (WhiteKing = 1 Or WhitePrince = 0) Then Response% = MsgBox("You can't leave your " + Pieces(Abs(OriginalPiece)).Name + " in Check! ", 0, "White"): Response% = 7
                End If
                Legal(SeeFile, SeeRank) = 0
                CheckLooked = 1
                If Response% <> 7 Then
                    If (OriginalPiece > 0 And (BlackKing = 1 Or BlackPrince = 0)) Or (OriginalPiece < 0 And (WhiteKing = 1 Or WhitePrince = 0)) And Choice <> "Tenjiku" And Choice <> "Maka" And Choice <> "Tai" Then
                        If OriginalPiece < 0 Then Turn2 = "White" Else Turn2 = "Black"
                        LookForMate
                    End If
                    SeeMove = OldSeeMove
                    If Choice = "Tenjiku" Or Choice = "Maka" Or Choice = "Tai" Then BestTally(0) = 0: Turn2 = Turn
                    If BestTally(0) = -999999 Then
                        If Turn2 = "Black" Then Board.PieceID.Caption = "Checkmate!  White wins." Else Board.PieceID.Caption = "Checkmate!  Black wins."
                        Notice = 5: BestTally(0) = -99999
                        GameOver = 1
                        Exit Sub
                    Else
                        If Response% <> 6 Then
                            Board.PieceID.Caption = Turn2 + " " + Pieces(Abs(OriginalPiece)).Name + " is in Check!"
                            Notice = 1
                        End If
                        Checked = 1
                        Exit Sub
                    End If
                Else
                    Checked = 2
                    SeeMove = OldSeeMove
                End If
            Else
                If CheckTest <> 1 Then
                L = 0
                Select Case Choice
                    Case "Heian", "Chu", "Dai", "Tenjiku": L = 1
                End Select
                If Squares(InitFile, InitRank) > 0 Then
                    BlackInfluence = 1
                    Board.ForeColor = &H606060
                Else
                    WhiteInfluence = 1
                    Board.ForeColor = &HFFFFFF
                End If
                Legal(SeeFile, SeeRank) = 0
                For EF = 2 To Pixels
                    If Reverse = 0 Then
                        If Squares(InitFile, InitRank) > 0 Then
                           Board.Line (XStart + ((InitFile - 1) * Pixels) + EF - 2 + L, 11 + ((InitRank - 1) * Pixels) + L)-(XStart + ((InitFile - 1) * Pixels) + EF - 2 + L, 11 + ((InitRank - 1) * Pixels) + PieceMask(Pieces(Abs(Squares(InitFile, InitRank))).Mask, EF) + 1)
                        Else
                           Board.Line (XStart + ((InitFile - 1) * Pixels) + (Pixels - EF) + L, 9 + (InitRank * Pixels) + L)-(XStart + ((InitFile - 1) * Pixels) + (Pixels - EF) + L, 8 + (InitRank * Pixels) - (PieceMask(Pieces(Abs(Squares(InitFile, InitRank))).Mask, EF) - (L * 2)))
                        End If
                    Else
                        If Squares(InitFile, InitRank) > 0 Then
                           Board.Line (XStart + ((BoardSizeX - InitFile) * Pixels + (Pixels - EF)) + L, 8 + ((BoardSizeY - InitRank + 1) * Pixels) + 1 + L)-(XStart + ((BoardSizeX - InitFile) * Pixels) + (Pixels - EF) + L, 8 + ((BoardSizeY - InitRank + 1) * Pixels) - PieceMask(Pieces(Abs(Squares(InitFile, InitRank))).Mask, EF) + (L * 2))
                        Else
                           Board.Line (XStart + ((BoardSizeX - InitFile) * Pixels) + EF - 2 + L, 10 + ((BoardSizeY - InitRank) * Pixels) + 1 + L)-(XStart + ((BoardSizeX - InitFile) * Pixels) + EF - 2 + L, 12 + ((BoardSizeY - InitRank) * Pixels) + PieceMask(Pieces(Abs(Squares(InitFile, InitRank))).Mask, EF))
                        End If
                    End If
                Next EF
                End If
            End If
            Legal(SeeFile, SeeRank) = 0
            Board.ForeColor = &H0&
            Board.FillColor = &HFFFFFF
        End If
    End If
End If
End If
End If
End If
End Sub

Sub Main()
If Screen.Width / Screen.TwipsPerPixelY > 650 Then Display = 800 Else Display = 640
If Screen.Width / Screen.TwipsPerPixelY > 810 Then Display = 1240
Load Start
If Start.ScaleWidth > 640 Then
    Unload Start
    Response% = MsgBox("This program will not run with LARGE FONTS. You must change your display settings to SMALL FONTS before running the program.", 0, "Shogi Variants 1.55a")
End If
End Sub

Sub MakeDrop()

File = CompLegal(BestMove).EndFile
Rank = CompLegal(BestMove).EndRank
For DD = 1 To Capture * 2
    If CompLegal(BestMove).EndPiece = CapRef(DD) Then I = DD
Next DD
HeldDrop
End Sub

Sub MakeMap()
For FF = 1 To BoardSizeY
    For GG = 1 To BoardSizeX
        Attacker(GG, FF) = 0: OldAttack(GG, FF) = 0
        BanMap(GG, FF).WhiteNum = 0: BackMap(GG, FF).WhiteNum = 0
        BanMap(GG, FF).BlackNum = 0: BackMap(GG, FF).BlackNum = 0
        BanMap(GG, FF).WhiteValue = 0: BackMap(GG, FF).WhiteValue = 0
        BanMap(GG, FF).BlackValue = 0: BackMap(GG, FF).BlackValue = 0
    Next GG
Next FF
FirstTime = 1
For FF = 1 To BoardSizeY
    For GG = 1 To BoardSizeX
        If Squares(GG, FF) <> 0 Then
            InitFile = GG: InitRank = FF
            Validate
        End If
    Next GG
Next FF
FirstTime = 0

End Sub

Sub MicroAdd()

If (MicroCap > 4 And MicroCap < 9) Or MicroCap > 12 Then
   InHand(MicroCap - 4) = InHand(MicroCap - 4) + 1
   Board.HandPic(MicroCap - 4).Visible = True
   If InHand(MicroCap - 4) > 1 Then Board.Held(MicroCap - 4).Caption = InHand(MicroCap - 4)
Else
   InHand(MicroCap + 4) = InHand(MicroCap + 4) + 1
   Board.HandPic(MicroCap + 4).Visible = True
   If InHand(MicroCap + 4) > 1 Then Board.Held(MicroCap + 4).Caption = InHand(MicroCap + 4)
End If

End Sub

Sub MicroDrop()

If (I < 5) Or (I > 8 And I < 13) Then
    InHand(I + 4) = InHand(I + 4) - 1
    If InHand(I + 4) < 1 Then Board.HandPic(I + 4).Visible = False
    If InHand(I + 4) < 2 Then Board.Held(I + 4).Caption = "" Else Board.Held(I - 4).Caption = InHand(I - 4)
Else
    InHand(I - 4) = InHand(I - 4) - 1
    If InHand(I - 4) < 1 Then Board.HandPic(I - 4).Visible = False
    If InHand(I - 4) < 2 Then Board.Held(I - 4).Caption = "" Else Board.Held(I - 4).Caption = InHand(I - 4)
End If

End Sub

Sub Move2()
For K = 1 To BoardSizeY
    For L = 1 To BoardSizeX
        If Grafix(L, K) = I Then
            InitFile = L
            InitRank = K
        End If
    Next L
Next K
Board.showpic(Grafix(InitFile, InitRank)).Drag 1
Board.PieceID.Caption = Pieces(Abs(Squares(InitFile, InitRank))).Name
End Sub

Sub MoveFormDrop()
If NewX > XStart And NewX < XStart + (BoardSizeX * Pixels) And NewY > 11 And NewY < 11 + (BoardSizeY * Pixels) Then
    GetSquare2
    Squares(File, Rank) = Squares(InitFile, InitRank)
    Squares(InitFile, InitRank) = 0
    Grafix(File, Rank) = I
    Grafix(InitFile, InitRank) = -1
    If Reverse = 0 Then
        Board.showpic(I).Move XStart + ((File - 1) * Pixels), 11 + ((Rank - 1) * Pixels)
    Else
        Board.showpic(I).Move XStart + ((BoardSizeX - File) * Pixels), 11 + ((BoardSizeY - Rank) * Pixels)
    End If
    ClearLegal
End If
End Sub

Sub MovePicDrop()
For K = 1 To BoardSizeY
    For L = 1 To BoardSizeX
        File = L: Rank = K
        If Grafix(L, K) = NewIndex Then
            If (L <> InitFile) Or (K <> InitRank) Then
                Board.showpic(I).Visible = False
                Grafix(L, K) = I
                Grafix(InitFile, InitRank) = -1
                Board.showpic(NewIndex).Visible = False
                Board.showpic(NewIndex).Move 0, 0
                If Reverse = 0 Then
                    Board.showpic(I).Move XStart + ((L - 1) * Pixels), 11 + ((K - 1) * Pixels)
                Else
                    Board.showpic(I).Move XStart + ((BoardSizeX - L) * Pixels), 11 + ((BoardSizeY - K) * Pixels)
                End If
                Board.showpic(I).Visible = True
                Victim$ = Pieces(Abs(Squares(File, Rank))).Name
                If Squares(File, Rank) > 0 And (Victim$ = "Prince" Or Victim$ = "Crown Prince") Then BlackPrince = BlackPrince - 1
                If Squares(File, Rank) < 0 And (Victim$ = "Prince" Or Victim$ = "Crown Prince") Then WhitePrince = WhitePrince - 1
                Squares(L, K) = Squares(InitFile, InitRank)
                Squares(InitFile, InitRank) = 0
            End If
        End If
    Next L
Next K
End Sub

Sub MovePieces()
Board.Refresh
Board.Caption = "Move Pieces with Left Mouse Button  (Press Right Mouse Button to Finish)"
MovePiece = 1
Board.BlackClock.Caption = "00:00:00"
Board.WhiteClock.Caption = "00:00:00"
Board.Timer1.Enabled = False

End Sub

Sub NextTurn()

If CompMove = 1 Then
    NextTurn2
Else
    If Notice < 1 Then Board.Caption = Cap
    Board.MnuHandicap.Enabled = False
    If (Choice = "Micro" Or Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tai") And Taken = 1 Then Promessage
    If Choice = "Chu" Then
        If Squares(File, Rank) = 2 And (Rank = 2 Or Rank = 3) Then NoPro = 1
        If Squares(File, Rank) = -2 And (Rank = 10 Or Rank = 11) Then NoPro = 1
        If Squares(File, Rank) = LastBlack And Taken <> 1 Then
            NoPro = 1
            LastBlack = 0
        End If
        If Squares(File, Rank) = LastWhite And Taken <> 1 Then
            NoPro = 1
            LastWhite = 0
        End If
        If Squares(File, Rank) > 0 Then LastBlack = 0 Else LastWhite = 0
    End If
    If Dropped <> 1 And NoPro <> 1 And Choice <> "Micro" Then
        If Squares(File, Rank) > 0 And (Rank <= PromDotY Or InitRank <= PromDotY) Then Promessage
        If Squares(File, Rank) < 0 And (Rank > BoardSizeY - PromDotY Or InitRank > BoardSizeY - PromDotY) Then Promessage
        If LionPro = 1 Then Promessage
    End If
    If Eval = 1 Then AddTally: Board.Caption = Cap + Space(90 - Len(Cap)) + "Evaluation: " + Str$(BestTally(1))
    NextTurn2
End If
End Sub

Sub NextTurn2()

LionVictim.Piece = 0
If Computer = Turn Then SeeMove = FirstSeeMove
If Eval = 1 Then Board.Caption = Cap + Space(90 - Len(Cap)) + "Evaluation: " + Str$(Int(BestTally(1)))
MakeMove = 0: Dropped = 0: NoPro = 0: LionPro = 0: CompMove = 0: Evaluate = 0
SetKings
If Turn = "Black" Then
    MoveCount = MoveCount + 1
    Turn = "White"
    WhiteLion = 0
    Board.MnuNextBlack.Enabled = True
    Board.MnuNextWhite.Enabled = False
    Board.MnuNextBlack.Checked = False
    Board.MnuNextWhite.Checked = True
 Else
    Turn = "Black"
    BlackLion = 0
    Board.MnuNextBlack.Enabled = False
    Board.MnuNextWhite.Enabled = True
    Board.MnuNextBlack.Checked = True
    Board.MnuNextWhite.Checked = False
End If
If Ligui <> 1 Then Convert
TurnCount = TurnCount + 1: EndTurn = TurnCount
Captures(TurnCount).number = 0
InitFile = 0: InitRank = 0: Teach = 0: Taken = 0: Ligui = 0
Board.LastMove.Caption = Format$(MoveCount) + ". " + ShortScore(TurnCount)
Score(TurnCount).Caption = ShortScore(TurnCount): CMove$ = ""
Board.Refresh
If (Turn = "White" And Squares(File, Rank) = 1 And BlackPrince = 0) Or (Turn = "Black" And Squares(File, Rank) = -1 And WhitePrince = 0) Then TwoKings
If Checked <> 2 Then
    OrigSeeMove = SeeMove: SeeMove = 1
    LookCheck
    SeeMove = OrigSeeMove
End If
If GameOver = 1 Then
    Score(TurnCount).Caption = Format$(MoveCount) + ". " + ShortScore(TurnCount) + " mate"
    Board.LastMove.Caption = Format$(MoveCount) + ". " + ShortScore(TurnCount) + " mate"
End If
If Checked = 2 Then TakeBack
If PawnMate = 1 Then TakeBack
Checked = 0: CheckTest = 0: CheckLooked = 0: PawnMate = 0: Mate = 0
If (Backwards = 1) Or (Choice <> "Chu" And Choice <> "Dai" And Choice <> "Tenjiku" And Choice <> "Maka" And Choice <> "DiaDai" And Choice <> "Tai") Then BugFix
If BlackEmperor = 1 And WhiteEmperor = 1 Then EmperorCheck
If ShowLast = 1 And Computer <> Turn Then FlashPiece
If Computer = Turn Then
    FirstSeeMove = SeeMove
    SeeMove = 1
    CompMain
End If
End Sub

Sub NoCompTeach()

Board.MnuVer2.Enabled = True
Board.MnuVer1.Enabled = False
Board.MnuVer1.Checked = True
Board.MnuVer2.Checked = False
TeachVer = 1
End Sub

Sub Notation()
If Notate = 0 Then
    Board.NotTop.Visible = False
    Board.NotSide.Visible = False
Else
    Board.NotTop.Visible = True
    Board.NotSide.Visible = True
End If
If Board.MnuNotOn.Enabled = False Then Board.MnuNotOn.Enabled = True Else Board.MnuNotOn.Enabled = False
If Board.MnuNotOff.Enabled = False Then Board.MnuNotOff.Enabled = True Else Board.MnuNotOff.Enabled = False
If Board.MnuNotOn.Checked = False Then Board.MnuNotOn.Checked = True Else Board.MnuNotOn.Checked = False
If Board.MnuNotOff.Checked = False Then Board.MnuNotOff.Checked = True Else Board.MnuNotOff.Checked = False
End Sub

Sub NotSet()
Board.AutoRedraw = True
For K = 1 To BoardSizeX
    Board.CurrentX = (XStart - 3) + ((K - 1) * Pixels) + Int(Pixels / 3)
    Board.CurrentY = 0
    If Choice <> "Chu" And Choice <> "Heian" And Choice <> "Dai" And Choice <> "Tenjiku" Then
        Board.CurrentX = Board.CurrentX - 1
        Board.CurrentY = Board.CurrentY - 1
    End If
    If Reverse = 0 Then Board.Print BoardSizeX - K + 1 Else Board.Print K
    Board.CurrentX = (XStart + 2) + (BoardSizeX * Pixels)
    Board.CurrentY = 11 + (K - 1) * Pixels + Int(Pixels / 3)
    If Choice <> "Chu" And Choice <> "Heian" And Choice <> "Dai" And Choice <> "Tenjiku" Then
        Board.CurrentX = Board.CurrentX - 1
        Board.CurrentY = Board.CurrentY - 1
    End If
    If K <= BoardSizeY Then
        If Reverse = 0 Then Board.Print Chr$(96 + K) Else Board.Print Chr$(96 + (BoardSizeY - K + 1))
    End If
Next K
If Choice = "Yari" Then
    Board.CurrentX = (XStart + 1) + (BoardSizeX * Pixels)
    Board.CurrentY = 11 + 7 * Pixels + Int(Pixels / 3)
    If Reverse = 0 Then Board.Print Chr$(104) Else Board.Print Chr$(98)
    Board.CurrentX = (XStart + 1) + (BoardSizeX * Pixels)
    Board.CurrentY = 11 + 8 * Pixels + Int(Pixels / 3)
    If Reverse = 0 Then Board.Print Chr$(105) Else Board.Print Chr$(97)
End If
If Choice = "Micro" Then
    Board.CurrentY = 270
    Board.CurrentX = 441
    If Reverse = 0 Then Board.Print Chr$(101) Else Board.Print Chr$(97)
End If
Board.AutoRedraw = False
End Sub

Sub PawnMates()
    
If CompLegal(AA).EndPiece <> 0 Then
    If (Pieces(Abs(CompLegal(AA).EndPiece)).Name = "Pawn" Or Pieces(Abs(CompLegal(AA).EndPiece)).Name = "Sparrow Pawn" Or Pieces(Abs(CompLegal(AA).EndPiece)).Name = "Swallow" Or Pieces(Abs(CompLegal(AA).EndPiece)).Name = "Dolphin") And CompLegal(AA).StartFile = 0 And Choice <> "Micro" And Choice <> "Yari" Then
        If Turn = "Black" And CompLegal(AA).EndRank > 1 Then
            If Squares(CompLegal(AA).EndFile, CompLegal(AA).EndRank - 1) = -1 Then
                PawnMate = 1
                For SS = CompLegal(AA).EndRank - 2 To CompLegal(AA).EndRank
                    For TT = CompLegal(AA).EndFile - 1 To CompLegal(AA).EndFile + 1
                        If TT > 0 And TT <= BoardSizeX And SS > 0 And SS <= BoardSizeY And (TT <> CompLegal(AA).EndFile Or SS <> CompLegal(AA).EndRank) Then
                            If BanMap(TT, SS).BlackNum = 0 And Squares(TT, SS) >= 0 Then PawnMate = 0
                        End If
                    Next TT
                Next SS
                If PawnMate = 1 Then WhiteTally = WhiteTally + 999999
            End If
        End If
        If Turn = "White" And CompLegal(AA).EndRank < BoardSizeY Then
            If Squares(CompLegal(AA).EndFile, CompLegal(AA).EndRank + 1) = 1 Then
                PawnMate = 1
                For SS = CompLegal(AA).EndRank To CompLegal(AA).EndRank + 2
                    For TT = CompLegal(AA).EndFile - 1 To CompLegal(AA).EndFile + 1
                        If TT > 0 And TT <= BoardSizeX And SS > 0 And SS <= BoardSizeY And (SS <> CompLegal(AA).EndRank Or TT <> CompLegal(AA).EndFile) Then
                            If BanMap(TT, SS).WhiteNum = 0 And Squares(TT, SS) <= 0 Then PawnMate = 0
                        End If
                    Next TT
                Next SS
                If PawnMate = 1 Then BlackTally = BlackTally + 999999
            End If
        End If
        PawnMate = 0
    End If
End If

End Sub

Sub PicDown()
If Computer <> Turn And Computer <> "Both" And Level <> 0 And GameOver <> 1 Then
Notice = 0
Board.PieceID.ForeColor = &HFF0000
If Handicap = 1 Or Reduce = 1 Or Selection <> 0 Or MovePiece = 1 Then
    RemovePiece
Else
    If LionPiece = -1 Then Board.Caption = Cap
    If LionPiece = I Or LionPiece = -1 Then
        K = 1
        Do
            L = 1
            Do
                If Grafix(L, K) = I Then
                    PieceName = Pieces(Abs(Squares(L, K))).Name
                    Board.PieceID.Caption = PieceName
                    InitFile = L
                    InitRank = K
                    Found = 1
                End If
                L = L + 1
            Loop Until L > BoardSizeX Or Found = 1
            K = K + 1
        Loop Until K > BoardSizeY Or Found = 1
        Found = 0
        If (Squares(InitFile, InitRank) > 0 And Turn = "Black") Or (Squares(InitFile, InitRank) < 0 And Turn = "White") Then
            Board.showpic(I).Drag 1
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Emperor" Then Emperor Else Validate
        Else
            Board.FillStyle = 1: Other = 1
            Board.ForeColor = &HC00000
            Validate
            Board.ForeColor = &H0
            Board.FillStyle = 0: Other = 0
        End If
    Else
        Board.PieceID.ForeColor = &HFF&
        Board.PieceID.Caption = "You must move your " + LionName$ + " !"
        Notice = 1
    End If
End If
End If
End Sub

Sub PicDrop()
If ShowLast = 1 Then Board.Refresh
Found = 0
If InitRank = 0 Then ClearLegal
If InitRank <> 0 And MovePiece <> 1 Then
K = 1
Do
    L = 1
    Do
        If Grafix(L, K) = NewIndex Then
            Found = 1: File = L: Rank = K
            If Legal(L, K) > 0 Then
                If LionPiece <> I Then
                    Score(TurnCount).IDStart = Squares(InitFile, InitRank)
                    Score(TurnCount).PosStart = (InitRank * (BoardSizeX + 1)) + InitFile
                    CMove$ = CMove$ + Trim$(Pieces(Abs(Squares(InitFile, InitRank))).sname)
                    CMove$ = CMove$ + Format$((BoardSizeX - InitFile) + 1) + Chr$(96 + InitRank)
                    If (Computer = Turn Or Computer = "Both") And LionVictim.Piece <> 0 Then
                        CMove$ = CMove$ + "x" + Format$((BoardSizeX - LionVictim.File) + 1) + Chr$(96 + LionVictim.Rank)
                    End If
                End If
                If Choice = "Chu" And Pieces(Abs(Squares(L, K))).Name = "Lion" And Pieces(Abs(Squares(InitFile, InitRank))).Name <> "Lion" Then
                    If Turn = "Black" Then BlackLion = 1 Else WhiteLion = 1
                End If
                If Legal(L, K) = 1 Then LionPiece = -1
                Board.Frame.Visible = False
                If Legal(L, K) = 4 Then
                    Score(TurnCount).IDEnd = Squares(InitFile, InitRank)
                    Score(TurnCount).PosEnd = Score(TurnCount).PosStart
                    CMove$ = CMove$ + "x!"
                Else
                    Score(TurnCount).IDEnd = Squares(File, Rank)
                    Score(TurnCount).PosEnd = (Rank * (BoardSizeX + 1)) + File
                    Board.showpic(I).Visible = False
                    Grafix(L, K) = I
                    If InitFile <> File Or InitRank <> Rank Then Grafix(InitFile, InitRank) = -1
                End If
                If Legal(L, K) <> 4 Then
                    If (InitFile <> File Or InitRank <> Rank) Then CMove$ = CMove$ + "x" Else CMove$ = CMove$ + "-"
                End If
                CMove$ = CMove$ + Format$((BoardSizeX - File) + 1) + Chr$(Rank + 96)
                Captures(TurnCount).number = Captures(TurnCount).number + 1
                Captures(TurnCount).Positions(Captures(TurnCount).number) = (Rank * (BoardSizeX + 1)) + File
                Captures(TurnCount).PieceNum(Captures(TurnCount).number) = Squares(File, Rank)
                If LionVictim.Piece <> 0 Then
                    Captures(TurnCount).number = Captures(TurnCount).number + 1
                    Captures(TurnCount).Positions(Captures(TurnCount).number) = (LionVictim.Rank * (BoardSizeX + 1)) + LionVictim.File
                    Captures(TurnCount).PieceNum(Captures(TurnCount).number) = Squares(LionVictim.File, LionVictim.Rank)
                End If
                Board.showpic(NewIndex).Visible = False
                Board.showpic(NewIndex).Move 0, 0
                If Abs(Squares(L, K)) = 1 Or Pieces(Abs(Squares(L, K))).Name = "Emperor" Or Pieces(Abs(Squares(L, K))).Name = "Crown Prince" Or Pieces(Abs(Squares(L, K))).Name = "Prince" Then CheckMate
                Taken = 1
                If Drop = 1 Then ChangeSides
                If Legal(File, Rank) = 3 Then
                    Score(TurnCount).IDEnd = 0
                    Grafix(File, Rank) = -1
                    Board.showpic(I).Move 0, 0
                    Squares(InitFile, InitRank) = 0
                    Squares(File, Rank) = 0
                    NoPro = 1
                 Else
                    If Legal(File, Rank) <> 4 Then
                        Squares(File, Rank) = Squares(InitFile, InitRank)
                        If Squares(File, Rank) = 1 Then BlackKingX = File: BlackKingY = Rank
                        If Squares(File, Rank) = -1 Then WhiteKingX = File: WhiteKingY = Rank
                        If Pieces(Abs(Squares(File, Rank))).Name = "Emperor" And Squares(File, Rank) > 0 Then BlackEmpX = File: BlackEmpY = Rank
                        If Pieces(Abs(Squares(File, Rank))).Name = "Emperor" And Squares(File, Rank) < 0 Then WhiteEmpX = File: WhiteEmpY = Rank
                        If Reverse = 0 Then
                            Board.showpic(I).Move XStart + ((File - 1) * Pixels), 11 + ((Rank - 1) * Pixels)
                        Else
                            Board.showpic(I).Move XStart + ((BoardSizeX - File) * Pixels), 11 + ((BoardSizeY - Rank) * Pixels)
                        End If
                        Board.showpic(I).Visible = True
                        If InitFile <> File Or InitRank <> Rank Then Squares(InitFile, InitRank) = 0
                        If LionVictim.Piece <> 0 Then
                            Squares(LionVictim.File, LionVictim.Rank) = 0
                            Board.showpic(Grafix(LionVictim.File, LionVictim.Rank)).Visible = False
                            Board.showpic(Grafix(LionVictim.File, LionVictim.Rank)).Move 0, 0
                            Grafix(LionVictim.File, LionVictim.Rank) = -1
                        End If
                    End If
                End If
                If Legal(L, K) = 4 Then Squares(L, K) = 0: Grafix(L, K) = -1: File = InitFile: Rank = InitRank
                If Demon = 1 Then Flame
                If Legal(L, K) = 3 Then CMove$ = CMove$ + "*"
                If Legal(L, K) = 6 Then Teach = 3
                If Legal(L, K) = 2 Then Teach = 2 Else Teach = 1
                If Mate <> 1 Then
                    If Legal(L, K) = 2 Or Legal(L, K) = 6 Then
                        DoubleMove
                    Else
                        LastPieceX = File: LastPieceY = Rank
                        If CompMove <> 1 Then NextTurn
                    End If
                End If
            End If
        End If
        L = L + 1
    Loop Until L > BoardSizeX Or Found = 1
    K = K + 1
Loop Until K > BoardSizeY Or Found = 1
Found = 0
ClearLegal
If Mate = 1 Then GameOver = 1: Response% = MsgBox("        Checkmate!          ", 0, Turn + " Wins!"): NextTurn
Else
    If MovePiece = 1 Then MovePicDrop
End If
End Sub

Sub PrintScore()
    
Printer.Print GameName + " Shogi -  Game Record"
Printer.Print "____________________________________"
Printer.Print

PrintMax = 4
PrintInc = 20
If Choice = "Chu" Or Choice = "Dai" Or Choice = "Maka" Or Choice = "DaiDai" Or Choice = "Tai" Then
    PrintMax = 3
    PrintInc = 27
End If
If Choice = "Tenjiku" Then
    PrintMax = 2
    PrintInc = 40
End If
K = 0: J = 0
For W = 1 To TurnCount Step 2
    K = K + 1: J = J + 1
    FirstScore = Score(W).Caption
    SecondScore = Score(W + 1).Caption
    If InStr(FirstScore, " ") > 0 Then TenjikuScore1
    If InStr(SecondScore, " ") > 0 Then TenjikuScore2
    If HandGame = 1 And W = 1 Then
    Printer.Print "1.  -  " + SecondScore; Tab(PrintInc);
    Else
    Printer.Print K + ". " + FirstScore + " " + SecondScore; Tab(J * PrintInc);
    End If
If J = PrintMax Then Printer.Print: J = 0
Next W
Board.Caption = "Printing...": Notice = 1
Printer.EndDoc
End Sub

Sub Promessage()
ClearLegal
ForceProm = 0: Taken = 0
If Choice = "Micro" Or Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tai" Then ForceProm = 1
If Pieces(Abs(Squares(File, Rank))).special = "1" Then
    If Squares(File, Rank) > 0 And Rank = 1 Then ForceProm = 1
    If Squares(File, Rank) < 0 And Rank = BoardSizeY Then ForceProm = 1
End If
If Pieces(Abs(Squares(File, Rank))).special = "2" Then
    If Squares(File, Rank) > 0 And Rank < 3 Then ForceProm = 1
    If Squares(File, Rank) < 0 And Rank > BoardSizeY - 2 Then ForceProm = 1
End If
If Prom = 0 And ForceProm <> 1 Then
    If Pieces(Abs(Squares(File, Rank))).Promotes > 0 Then
        If AutoPromote <> 1 Then
            L$ = Pieces(Pieces(Abs(Squares(File, Rank))).Promotes).Name
            K$ = Pieces(Abs(Squares(File, Rank))).Name
            Message$ = "Promote to " & L$ & " ?"
            Response% = MsgBox(Message$, 36, K$)
            If Response% = 6 Then
                Promote
            Else
                CMove$ = CMove$ + "="
                If Turn = "White" And InitRank < 9 Then LastWhite = Squares(File, Rank)
                If Turn = "Black" And InitRank > 4 Then LastBlack = Squares(File, Rank)
            End If
        Else
            Promote
        End If
    End If
End If
If Prom = 1 Or ForceProm = 1 Then
    If Pieces(Abs(Squares(File, Rank))).Promotes > 0 Then
        Board.PieceID.ForeColor = &H8000&
        K$ = Pieces(Abs(Squares(File, Rank))).Name
        Board.PieceID.Caption = K$ + " promotes"
        Notice = 1
        Promote
    End If
End If
End Sub

Sub Promote()

If Reverse = 0 Then PromGraf = (TotGraph / 2) - 1 Else PromGraf = -1
If Squares(File, Rank) < 0 And Pieces(Abs(Squares(File, Rank))).Promotes <> 0 Then
    If Choice = "Tai" Then
        Board.showpic(I).Picture = TaiPieces.Pix(PromGraf + Pieces(Abs(Squares(File, Rank))).PrGraphic).Picture
    Else
        Board.showpic(I).Picture = Board.Pix(PromGraf + Pieces(Abs(Squares(File, Rank))).PrGraphic).Picture
    End If
    PromPiece$ = Pieces(Abs(Squares(File, Rank))).Name
    If PromPiece$ = "Drunk Elephant" Then WhitePrince = WhitePrince + 1
    If PromPiece$ = "King" Then
        WhiteEmperor = 1: WhiteEmpX = File: WhiteEmpY = Rank
    End If
    Squares(File, Rank) = 0 - Pieces(Abs(Squares(File, Rank))).Promotes
    Score(TurnCount).IDEnd = Squares(File, Rank)
    Board.showpic(I).Visible = True
    CMove$ = CMove$ + "+"
    If AutoPromote = 1 And ForceProm <> 1 Then AutoMessage
End If
If Reverse = 1 Then PromGraf = (TotGraph / 2) - 1 Else PromGraf = -1
If Squares(File, Rank) > 0 And Pieces(Abs(Squares(File, Rank))).Promotes <> 0 Then
    If Choice = "Tai" Then
        Board.showpic(I).Picture = TaiPieces.Pix(PromGraf + Pieces(Squares(File, Rank)).PrGraphic).Picture
    Else
        Board.showpic(I).Picture = Board.Pix(PromGraf + Pieces(Squares(File, Rank)).PrGraphic).Picture
    End If
    PromPiece$ = Pieces(Abs(Squares(File, Rank))).Name
    If PromPiece$ = "Drunk Elephant" Then BlackPrince = BlackPrince + 1
    If PromPiece$ = "King" Then
        BlackEmperor = 1: BlackEmpX = File: BlackEmpY = Rank
    End If
    Squares(File, Rank) = Pieces(Abs(Squares(File, Rank))).Promotes
    Score(TurnCount).IDEnd = Squares(File, Rank)
    Board.showpic(I).Visible = True
    CMove$ = CMove$ + "+"
    If AutoPromote = 1 And ForceProm <> 1 Then AutoMessage
End If
End Sub

Sub RangeJump()
M = 64: Range = 1
SingleStep
End Sub

Sub ReduceHand()

If Replaying = 1 Then
    CaptPiece = Score(TurnCount).IDEnd
    OldPiece = Squares(InitFile, InitRank)
    Squares(InitFile, InitRank) = 0 - CaptPiece
Else
If Pieces(Abs(Squares(InitFile, InitRank))).Promotes = 0 And Pieces(Abs(Squares(InitFile, InitRank))).PrGraphic > 0 Then
    CaptPiece = Pieces(Abs(Squares(InitFile, InitRank))).PrGraphic
    If Squares(InitFile, InitRank) > 0 Then CaptPiece = 0 - CaptPiece
Else
    CaptPiece = 0 - Squares(InitFile, InitRank)
End If
End If
For Z = 1 To Capture
    If (Squares(InitFile, InitRank) < 0 And Reverse = 0) Or (Squares(InitFile, InitRank) > 0 And Reverse = 1) Then
        If CapRef(Z) = CaptPiece Then
            InHand(Z) = InHand(Z) - 1
            If InHand(Z) < 2 Then Board.Held(Z).Caption = "" Else Board.Held(Z).Caption = InHand(Z)
            If InHand(Z) < 1 Then Board.HandPic(Z).Visible = False
            If Choice = "Micro" Then
                I = Z: MicroDrop
            End If
        End If
    Else
        If CapRef(Z) = 0 - CaptPiece Then
            InHand(Capture + Z) = InHand(Capture + Z) - 1
            If InHand(Capture + Z) < 2 Then Board.Held(Capture + Z).Caption = "" Else Board.Held(Capture + Z).Caption = InHand(Capture + Z)
            If InHand(Capture + Z) < 1 Then Board.HandPic(Capture + Z).Visible = False
            If Choice = "Micro" Then
                I = Capture + Z: MicroDrop
            End If
         End If
    End If
Next Z
If Replaying = 1 Then Squares(InitFile, InitRank) = OldPiece
End Sub

Sub ReduceHand2()
If Replaying = 1 Then
    CaptPiece = Score(TurnCount).IDEnd
    OldPiece = Squares(InitFile, InitRank)
    Squares(InitFile, InitRank) = 0 - CaptPiece
Else
If Pieces(Abs(Squares(InitFile, InitRank))).Promotes = 0 And Pieces(Abs(Squares(InitFile, InitRank))).PrGraphic > 0 Then
    CaptPiece = Pieces(Abs(Squares(InitFile, InitRank))).PrGraphic
    If Squares(InitFile, InitRank) > 0 Then CaptPiece = 0 - CaptPiece
Else
    CaptPiece = 0 - Squares(InitFile, InitRank)
End If
End If
For Z = 1 To Capture
    If (Squares(InitFile, InitRank) < 0 And Reverse = 0) Or (Squares(InitFile, InitRank) > 0 And Reverse = 1) Then
        If CapRef(Z) = CaptPiece Then
            InHand(Z) = InHand(Z) - 1
            If Choice = "Micro" Then
                I = Z
                If (I < 5) Or (I > 8 And I < 13) Then InHand(I + 4) = InHand(I + 4) - 1 Else InHand(I - 4) = InHand(I - 4) - 1
            End If
        End If
    Else
        If CapRef(Z) = 0 - CaptPiece Then
            InHand(Capture + Z) = InHand(Capture + Z) - 1
            If Choice = "Micro" Then
                I = Capture + Z
                If (I < 5) Or (I > 8 And I < 13) Then InHand(I + 4) = InHand(I + 4) - 1 Else InHand(I - 4) = InHand(I - 4) - 1
            End If
         End If
    End If
Next Z
If Replaying = 1 Then Squares(InitFile, InitRank) = OldPiece

End Sub

Sub RemovePiece()
If Selection <> 0 Or MovePiece = 1 Then
    SquareReplace
Else
K = 1
Do
    L = 1
    Do
        If Grafix(L, K) = I Then
            PieceName = Pieces(Abs(Squares(L, K))).Name
            Board.PieceID.Caption = PieceName
            File = L
            Rank = K
        End If
        L = L + 1
    Loop Until L > BoardSizeX Or Found = 1
    K = K + 1
Loop Until K > BoardSizeY Or Found = 1
Found = 0
If Handicap = 1 Then
    If Squares(File, Rank) > 0 Then
        Board.PieceID.ForeColor = &HFF&
        Board.PieceID.Caption = "Select a White piece"
        Notice = 1
    End If
    If Squares(File, Rank) < 0 Then
        Victim$ = Pieces(Abs(Squares(File, Rank))).Name
        If Abs(Squares(File, Rank)) = 1 Or Victim$ = "Emperor" Or Victim$ = "Prince" Or Victim$ = "Crown Prince" Then
            Board.PieceID.ForeColor = &HFF&
            Board.PieceID.Caption = "The White " + Victim$ + "can not be removed"
            Notice = 1
        Else
            Board.PieceID.Caption = Pieces(Abs(Squares(File, Rank))).Name + " removed"
            Notice = 1
            Squares(File, Rank) = 0
            Board.showpic(Grafix(File, Rank)).Visible = False
            Board.showpic(Grafix(File, Rank)).Move 0, 0
            Grafix(File, Rank) = -1
            Turn = "White"
            Board.NextMove.Caption = "White to Move"
            MoveCount = 1: HandGame = 1
        End If
    End If
Else
    Board.PieceID.Caption = ""
    Victim$ = Pieces(Abs(Squares(File, Rank))).Name
    If Squares(File, Rank) > 0 And (Victim$ = "Prince" Or Victim$ = "Crown Prince") Then BlackPrince = BlackPrince - 1
    If Squares(File, Rank) < 0 And (Victim$ = "Prince" Or Victim$ = "Crown Prince") Then WhitePrince = WhitePrince - 1
    Squares(File, Rank) = 0
    Board.showpic(Grafix(File, Rank)).Visible = False
    Board.showpic(Grafix(File, Rank)).Move 0, 0
    Grafix(File, Rank) = -1
    MoveCount = 0: TurnCount = 0
    If Turn = "White" Then MoveCount = 1
    Board.LastMove.Caption = ""
End If
End If
End Sub

Sub ReorderMoves()

If Level > 1 Then
    For XX = 1 To TestDepth
        If BestTally(Level + 1) > BestTally(XX) Then
            For YY = TestDepth - 1 To XX Step -1
                BestTally(YY + 1) = BestTally(YY)
                MoveList(YY + 1).StartPiece = MoveList(YY).StartPiece
                MoveList(YY + 1).EndPiece = MoveList(YY).EndPiece
                MoveList(YY + 1).StartFile = MoveList(YY).StartFile
                MoveList(YY + 1).EndFile = MoveList(YY).EndFile
                MoveList(YY + 1).StartRank = MoveList(YY).StartRank
                MoveList(YY + 1).EndRank = MoveList(YY).EndRank
                OldKingTally(YY + 1) = OldKingTally(YY)
                If Choice = "Dai" Or Choice = "Chu" Or Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tenjiku" Or Choice = "Tai" Then
                    ECapture(YY + 1).Piece = ECapture(YY).Piece
                    ECapture(YY + 1).File = ECapture(YY).File
                    ECapture(YY + 1).Rank = ECapture(YY).Rank
                End If
            Next YY
            BestTally(XX) = BestTally(Level + 1)
            MoveList(XX).StartPiece = CompLegal(BestMove).StartPiece
            MoveList(XX).EndPiece = CompLegal(BestMove).EndPiece
            MoveList(XX).StartFile = CompLegal(BestMove).StartFile
            MoveList(XX).EndFile = CompLegal(BestMove).EndFile
            MoveList(XX).StartRank = CompLegal(BestMove).StartRank
            MoveList(XX).EndRank = CompLegal(BestMove).EndRank
            OldKingTally(XX) = KingTally(BestMove)
            If Choice = "Dai" Or Choice = "Chu" Or Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tenjiku" Or Choice = "Tai" Then
                ECapture(XX).Piece = ExtraCapture(BestMove).Piece
                ECapture(XX).File = ExtraCapture(BestMove).File
                ECapture(XX).Rank = ExtraCapture(BestMove).Rank
            End If
            Exit Sub
        End If
        DoEvents
    Next XX
End If

End Sub

Sub Replay()

If (LegalMoves = 0 Or Checked = 2) And LionPiece <> I And XA = 0 Then
Notice = 0
Board.PieceID.Caption = ""
If Forwards <> 1 Then Board.Caption = Cap
BugFix
If TurnCount >= EndTurn Then
    Board.PieceID.ForeColor = &HFF&
    Board.PieceID.Caption = "No moves to replay!"
    Notice = 1
Else
    Replaying = 1
    For V = 1 To Captures(TurnCount).number
       Location = Captures(TurnCount).Positions(V)
       InitRank = Int(Location / (BoardSizeX + 1))
       InitFile = Location - (InitRank * (BoardSizeX + 1))
       NewGraf = Grafix(InitFile, InitRank)
       Grafix(InitFile, InitRank) = -1
       Board.showpic(NewGraf).Visible = False
       Board.showpic(NewGraf).Move 0, 0
       Squares(InitFile, InitRank) = 0
    Next V
    If Drop = 1 And Captures(TurnCount).number > 0 Then
         CaptPiece = Captures(TurnCount).PieceNum(1)
         If Pieces(Abs(CaptPiece)).Promotes = 0 And Pieces(Abs(CaptPiece)).PrGraphic > 0 Then
            CaptPiece = Pieces(Abs(CaptPiece)).PrGraphic
            If Captures(TurnCount).PieceNum(1) > 0 Then CaptPiece = 0 - CaptPiece
         Else
            CaptPiece = 0 - CaptPiece
         End If
         AddHand
    End If
    Location = Score(TurnCount).PosStart
    If Location > 0 Then
        Rank = Int(Location / (BoardSizeX + 1))
        File = Location - (Rank * (BoardSizeX + 1))
        Squares(File, Rank) = 0
        NewGraf = Grafix(File, Rank)
        Grafix(File, Rank) = -1
        Board.showpic(NewGraf).Visible = False
        Board.showpic(NewGraf).Move 0, 0
    End If
    Location = Score(TurnCount).PosEnd
    If Location > 0 Then
        InitRank = Int(Location / (BoardSizeX + 1))
        InitFile = Location - (InitRank * (BoardSizeX + 1))
        Squares(InitFile, InitRank) = Score(TurnCount).IDStart
        If Sgn(Score(TurnCount).IDStart) = Sgn(Score(TurnCount).IDEnd) And Score(TurnCount).IDEnd <> Score(TurnCount).IDStart Then Squares(InitFile, InitRank) = Score(TurnCount).IDEnd
        If Squares(InitFile, InitRank) < 0 Then
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Emperor" Then WhiteEmpX = InitFile: WhiteEmpY = InitRank
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "King" Then WhiteKingX = InitFile: WhiteKingY = InitRank
        End If
        If Squares(InitFile, InitRank) > 0 Then
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Emperor" Then BlackEmpX = InitFile: BlackEmpY = InitRank
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "King" Then BlackKingX = InitFile: BlackKingY = InitRank
        End If
        If Score(TurnCount).IDEnd <> 0 Then
            NewGraf = 0
            Do While Board.showpic(NewGraf).Visible = True
                NewGraf = NewGraf + 1
            Loop
            SetGrafix
        End If
    End If
    If Drop = 1 And Score(TurnCount).PosStart = 0 Then ReduceHand
    If Turn = "Black" Then
        Turn = "White"
        Board.NextMove.Caption = "White to Move"
        MoveCount = MoveCount + 1
    Else
        Turn = "Black"
        Board.NextMove.Caption = "Black to Move"
    End If
    TurnCount = TurnCount + 1
    Board.MnuHandicap.Enabled = False
    If Asc(Score(TurnCount).Caption) > 47 And Asc(Score(TurnCount).Caption) < 58 Then
        Board.LastMove.Caption = Score(TurnCount).Caption
    Else
        Board.LastMove.Caption = Format$(MoveCount) + ". " + Score(TurnCount).Caption
    End If
    Backwards = 1
    SetKings
    Location = Score(TurnCount - 1).PosEnd
    If Location > 0 Then
        Rank = Int(Location / (BoardSizeX + 1))
        File = Location - (Rank * (BoardSizeX + 1))
    End If
    LastPieceX = File: LastPieceY = Rank
    If Computer = "Black" Or Computer = "White" Then
        Board.Caption = "Move Replayed (" + Str$(TurnCount) + " of" + Str$(EndTurn) + " ) : Press [ESC] to continue play."
    Else
        Board.Caption = "Move Replayed (" + Str$(TurnCount) + " of" + Str$(EndTurn) + " )"
    End If
End If
Replaying = 0
End If

End Sub

Sub Replay2()
If (LegalMoves = 0 Or Checked = 2) And LionPiece <> I And XA = 0 Then
If TurnCount < EndTurn Then
    Replaying = 1
    For V = 1 To Captures(TurnCount).number
       Location = Captures(TurnCount).Positions(V)
       InitRank = Int(Location / (BoardSizeX + 1))
       InitFile = Location - (InitRank * (BoardSizeX + 1))
       Squares(InitFile, InitRank) = 0
    Next V
    If Drop = 1 And Captures(TurnCount).number > 0 Then
         CaptPiece = Captures(TurnCount).PieceNum(1)
         If Pieces(Abs(CaptPiece)).Promotes = 0 And Pieces(Abs(CaptPiece)).PrGraphic > 0 Then
            CaptPiece = Pieces(Abs(CaptPiece)).PrGraphic
            If Captures(TurnCount).PieceNum(1) > 0 Then CaptPiece = 0 - CaptPiece
         Else
            CaptPiece = 0 - CaptPiece
         End If
         AddHand3
    End If
    Location = Score(TurnCount).PosStart
    If Location > 0 Then
        Rank = Int(Location / (BoardSizeX + 1))
        File = Location - (Rank * (BoardSizeX + 1))
        Squares(File, Rank) = 0
    End If
    Location = Score(TurnCount).PosEnd
    If Location > 0 Then
        InitRank = Int(Location / (BoardSizeX + 1))
        InitFile = Location - (InitRank * (BoardSizeX + 1))
        Squares(InitFile, InitRank) = Score(TurnCount).IDStart
        If Sgn(Score(TurnCount).IDStart) = Sgn(Score(TurnCount).IDEnd) And Score(TurnCount).IDEnd <> Score(TurnCount).IDStart Then Squares(InitFile, InitRank) = Score(TurnCount).IDEnd
        If Squares(InitFile, InitRank) < 0 Then
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Emperor" Then WhiteEmpX = InitFile: WhiteEmpY = InitRank
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "King" Then WhiteKingX = InitFile: WhiteKingY = InitRank
        End If
        If Squares(InitFile, InitRank) > 0 Then
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Emperor" Then BlackEmpX = InitFile: BlackEmpY = InitRank
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "King" Then BlackKingX = InitFile: BlackKingY = InitRank
        End If
    End If
    If Drop = 1 And Score(TurnCount).PosStart = 0 Then ReduceHand2
    If Turn = "Black" Then
        Turn = "White"
        Board.NextMove.Caption = "White to Move"
        MoveCount = MoveCount + 1
    Else
        Turn = "Black"
        Board.NextMove.Caption = "Black to Move"
    End If
    TurnCount = TurnCount + 1
    Board.MnuHandicap.Enabled = False
    If Asc(Score(TurnCount).Caption) > 47 And Asc(Score(TurnCount).Caption) < 58 Then
        Board.LastMove.Caption = Score(TurnCount).Caption
    Else
        Board.LastMove.Caption = Format$(MoveCount) + ". " + Score(TurnCount).Caption
    End If
    Board.MnuHandicap.Enabled = False
    Backwards = 1
    If Location > 0 Then
        Rank = Int(Location / (BoardSizeX + 1))
        File = Location - (Rank * (BoardSizeX + 1))
    End If
    LastPieceX = File: LastPieceY = Rank
End If
Replaying = 0
End If

End Sub

Sub ReplayAll()
If LegalMoves = 0 Then
    Do While TurnCount < EndTurn
        Replay2
    Loop
    Board.Caption = Cap
    RestoreGrafix
    SetKings
End If
End Sub

Sub ResetBoard()

Board.Hide
If Choice = "Wa" Then
    For W = 1 To Capture * 2
       Board.Held(W).Caption = ""
       Board.HandPic(W).Visible = False
    Next W
End If
NewGame = 1
SetPieces

End Sub

Sub ResetHand()
For X = 1 To Capture
    If InHand(X) < 1 Then Board.HandPic(X).Visible = False
    If InHand(X) < 2 Then Board.Held(X).Caption = ""
    If InHand(Capture + X) < 1 Then Board.HandPic(Capture + X).Visible = False
    If InHand(Capture + X) < 2 Then Board.Held(Capture + X).Caption = ""
Next X
End Sub

Sub ResetLegal()

For MM = 1 To BoardSizeY
    For NN = 1 To BoardSizeX
        Legal(NN, MM) = 0
    Next NN
Next MM

End Sub

Sub RestoreGrafix()
     
 
 Board.Hide
 Count = 0: M = 0
 For J = 1 To BoardSizeY
    For I = 1 To BoardSizeX
        Grafix(I, J) = -1
        If Squares(I, J) <> 0 Then
            Graphnum = Pieces(Abs(Squares(I, J))).Graphic
            If (Squares(I, J) < 0 And Reverse = 0) Or (Squares(I, J) > 0 And Reverse = 1) Then Graphnum = Graphnum + (TotGraph / 2)
            If Choice = "Tai" Then Board.showpic(Count) = TaiPieces.Pix(Graphnum - 1) Else Board.showpic(Count) = Board.Pix(Graphnum - 1)
            If Reverse = 0 Then
                Board.showpic(Count).Move XStart + ((I - 1) * Pixels), 11 + ((J - 1) * Pixels)
            Else
                Board.showpic(Count).Move XStart + ((BoardSizeX - I) * Pixels), 11 + ((BoardSizeY - J) * Pixels)
            End If
            Board.showpic(Count).Visible = True
            Grafix(I, J) = Count
            Count = Count + 1
        End If
    Next I
 Next J
 If Drop = 1 Or Choice = "Wa" Then
     For I = 1 To Capture * 2
        Graphnum = Pieces(Abs(CapRef(I))).Graphic
        If I > Capture Then Graphnum = Graphnum + (TotGraph / 2)
        Board.HandPic(I) = Board.Pix(Graphnum - 1)
        Board.HandPic(I).Visible = False
        Board.Held(I).Caption = ""
        If InHand(I) > 0 Then Board.HandPic(I).Visible = True
        If InHand(I) > 1 Then Board.Held(I).Caption = InHand(I)
    Next I
End If
BugFix
Board.Show
If Choice = "Tai" Or Choice = "Maka" Then
    For ABC = 1 To BoardSizeY
        For DEF = 1 To BoardSizeX
            If Squares(DEF, ABC) > 0 Then
                If Pieces(Abs(Squares(DEF, ABC))).Name = "Emperor" Then BlackEmpX = DEF: BlackEmpY = ABC: BlackEmperor = 1
            End If
            If Squares(DEF, ABC) < 0 Then
                If Pieces(Abs(Squares(DEF, ABC))).Name = "Emperor" Then WhiteEmpX = DEF: WhiteEmpY = ABC: WhiteEmperor = 1
            End If
        Next DEF
    Next ABC
End If

End Sub

Sub RestoreMap()
For JJ = 1 To BoardSizeY
    For KK = 1 To BoardSizeX
        BanMap(KK, JJ).WhiteNum = BackMap(KK, JJ).WhiteNum
        BanMap(KK, JJ).BlackNum = BackMap(KK, JJ).BlackNum
        Attacker(KK, JJ) = OldAttack(KK, JJ)
        For LL = 1 To OldAttack(KK, JJ)
            BanMap(KK, JJ).Info(LL).File = BackMap(KK, JJ).Info(LL).File
            BanMap(KK, JJ).Info(LL).Rank = BackMap(KK, JJ).Info(LL).Rank
            BanMap(KK, JJ).Info(LL).Piece = BackMap(KK, JJ).Info(LL).Piece
        Next LL
    Next KK
    DoEvents
Next JJ

End Sub

Sub Rotate()

If LegalMoves = 0 Then
Board.Picture = LoadPicture(Direct + "\Data\" + Boardbmp)
If Reverse = 1 Then
    Reverse = 0
    Board.White.Picture = LoadPicture(Direct + "\Data\" + "WhiteDn.bmp")
    Board.Black.Picture = LoadPicture(Direct + "\Data\" + "BlackUp.bmp")
Else
    Reverse = 1
    Board.White.Picture = LoadPicture(Direct + "\Data\" + "WhiteUp.bmp")
    Board.Black.Picture = LoadPicture(Direct + "\Data\" + "BlackDn.bmp")
End If
For J = 1 To BoardSizeY
    For I = 1 To BoardSizeX
        If Squares(I, J) <> 0 Then
            Board.showpic(Grafix(I, J)).Visible = False
            Graphnum = Pieces(Abs(Squares(I, J))).Graphic
            If (Squares(I, J) < 0 And Reverse = 0) Or (Squares(I, J) > 0 And Reverse = 1) Then Graphnum = Graphnum + (TotGraph / 2)
            If Choice = "Tai" Then Board.showpic(Grafix(I, J)) = TaiPieces.Pix(Graphnum - 1) Else Board.showpic(Grafix(I, J)) = Board.Pix(Graphnum - 1)
            If Reverse = 0 Then
                Board.showpic(Grafix(I, J)).Move XStart + ((I - 1) * Pixels), 11 + ((J - 1) * Pixels)
            Else
                Board.showpic(Grafix(I, J)).Move XStart + ((BoardSizeX - I) * Pixels), 11 + ((BoardSizeY - J) * Pixels)
            End If
            Board.showpic(Grafix(I, J)).Visible = True
        End If
    Next I
Next J
If Drop = 1 Then
    ReDim TempHand(Capture * 2) As Integer
    For I = 1 To Capture * 2
        Board.HandPic(I).Visible = False
        Board.Held(I).Caption = ""
        CapRef(I) = 0 - CapRef(I)
        If I > Capture Then TempHand(I) = InHand(I - Capture) Else TempHand(I) = InHand(I + Capture)
    Next I
    For I = 1 To Capture * 2
        InHand(I) = TempHand(I)
        If InHand(I) > 0 Then Board.HandPic(I).Visible = True
        If InHand(I) > 1 Then Board.Held(I).Caption = InHand(I)
    Next I
End If
NotSet
End If
End Sub

Sub SaveGame()

On Error Resume Next
Board.CMSave.DialogTitle = "Save Game"
Board.CMSave.Flags = &H400& Or &H800& Or &H4&
Board.CMSave.Action = 2
If Err = 32755 Then Exit Sub
Saved$ = Board.CMSave.FileName

Open Saved$ For Output As #2
Write #2, Choice, Drop, MoveCount, Turn, Notate, SeeMove, TurnCount, WhiteKing, BlackKing
Write #2, WhiteLion, BlackLion, WhitePrince, BlackPrince, WhiteEmperor, BlackEmperor, Board.LastMove.Caption
Write #2, Board.WhiteClock.Caption, Board.BlackClock.Caption, HandGame, Reverse
For W = 0 To TurnCount
    Write #2, Score(W).Caption, Score(W).IDStart, Score(W).IDEnd, Score(W).PosStart, Score(W).PosEnd
    Write #2, Captures(W).number
    For V = 1 To Captures(W).number
        Write #2, Captures(W).Positions(V)
        Write #2, Captures(W).PieceNum(V)
    Next V
Next W
For W = 1 To BoardSizeY
    For Z = 1 To BoardSizeX
        Write #2, Squares(Z, W)
    Next Z
Next W
If Drop = 1 Or Choice = "Wa" Then
    For W = 1 To Capture * 2
        Write #2, InHand(W)
    Next W
End If
Answer$ = InputBox$("Please enter a short description of the game.", "Saved Game Description", SaveTitle$)
If Answer$ <> "" Then Write #2, Answer$ Else Write #2, "Saved Game - No Title"
Write #2, Computer
Write #2, Level
Write #2, GameOver
Write #2, Threat
Close #2
End Sub

Sub SeeMoves()

If Board.MnuShowOn.Enabled = False Then Board.MnuShowOn.Enabled = True Else Board.MnuShowOn.Enabled = False
If Board.MnuShowOff.Enabled = False Then Board.MnuShowOff.Enabled = True Else Board.MnuShowOff.Enabled = False
If Board.MnuShowOn.Checked = False Then Board.MnuShowOn.Checked = True Else Board.MnuShowOn.Checked = False
If Board.MnuShowOff.Checked = False Then Board.MnuShowOff.Checked = True Else Board.MnuShowOff.Checked = False
If SeeMove = 1 Then
    Board.PieceID.Caption = "Show Legal Moves - On"
    Board.MnuThreatOn.Enabled = True
    If OldThreat = "On" Then
        Threat = "On"
        SetThreat
        OldThreat = "None"
    Else
        Threat = "Off"
        Board.MnuThreatOn.Enabled = False
        SetThreat
        OldThreat = "None"
    End If
Else
    Board.PieceID.Caption = "Show Legal Moves - Off"
    OldThreat = Threat
    Threat = "Off"
    SetThreat
    Board.MnuThreatOn.Enabled = False
End If
Notice = 1
End Sub

Sub SetAutoPromote()
If Board.MnuAutoOn.Enabled = False Then Board.MnuAutoOn.Enabled = True Else Board.MnuAutoOn.Enabled = False
If Board.MnuAutoOff.Enabled = False Then Board.MnuAutoOff.Enabled = True Else Board.MnuAutoOff.Enabled = False
If Board.MnuAutoOn.Checked = False Then Board.MnuAutoOn.Checked = True Else Board.MnuAutoOn.Checked = False
If Board.MnuAutoOff.Checked = False Then Board.MnuAutoOff.Checked = True Else Board.MnuAutoOff.Checked = False
If AutoPromote = 1 Then
    Board.PieceID.Caption = "Auto-Promote On"
Else
    Board.PieceID.Caption = "Auto-Promote Off"
End If
Notice = 1
End Sub

Sub SetBlackPlayer()

If Board.MnuBlackPlayer.Enabled = False Then Board.MnuBlackPlayer.Enabled = True Else Board.MnuBlackPlayer.Enabled = False
If Board.MnuBlackComp.Enabled = False Then Board.MnuBlackComp.Enabled = True Else Board.MnuBlackComp.Enabled = False
If Board.MnuBlackPlayer.Checked = False Then Board.MnuBlackPlayer.Checked = True Else Board.MnuBlackPlayer.Checked = False
If Board.MnuBlackComp.Checked = False Then Board.MnuBlackComp.Checked = True Else Board.MnuBlackComp.Checked = False
If Choice = "Tai" Or Choice = "Maka" Then
    If Computer = "White" Or Computer = "Black" Or Computer = "Both" Then CompTeach Else NoCompTeach
End If
If Computer = "Both" Then CompVComp

End Sub

Sub SetClock()
If Notice > 0 Then Notice = Notice + 1
If Notice = 4 And Checked <> 1 Then
    Board.PieceID.Caption = ""
    Notice = 0
    If Board.Caption <> SaveTitle$ Then Board.Caption = Cap
End If
Secs = Val(Right$(Elapsed$, 2))
Mins = Val(Mid$(Elapsed$, 4, 2))
Hrs = Val(Left$(Elapsed$, 2))
Secs = Secs + 1
If Secs = 60 Then Secs = 0: Mins = Mins + 1
If Mins = 60 Then Mins = 0: Hrs = Hrs + 1
If Hrs = 100 Then Hrs = 0
Hours$ = LTrim$(Str$(Hrs))
Minutes$ = LTrim$(Str$(Mins))
Seconds$ = LTrim$(Str$(Secs))
If Len(Hours$) = 1 Then Hours$ = "0" + Hours$
If Len(Minutes$) = 1 Then Minutes$ = "0" + Minutes$
If Len(Seconds$) = 1 Then Seconds$ = "0" + Seconds$
Elapsed$ = Hours$ + ":" + Minutes$ + ":" + Seconds$
End Sub

Sub SetDifficulty()

If Grade = "Weak" Then
    Board.MnuWeak.Enabled = False
    Board.MnuWeak.Checked = True
    Board.MnuBest.Visible = False
    Board.MnuLessWeak.Enabled = True
    Board.MnuLessWeak.Checked = False
End If
If Choice = "Chu" Or Choice = "Dai" Or Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tai" Then Board.MnuLessWeak.Visible = False
If Grade = "LessWeak" Then
    Board.MnuWeak.Enabled = True
    Board.MnuWeak.Checked = False
    Board.MnuBest.Visible = False
    Board.MnuLessWeak.Enabled = False
    Board.MnuLessWeak.Checked = True
End If
Board.MnuBest.Visible = False
SetGrade
End Sub

Sub SetEval()

If Board.MnuEvalOn.Enabled = False Then Board.MnuEvalOn.Enabled = True Else Board.MnuEvalOn.Enabled = False
If Board.MnuEvalOff.Enabled = False Then Board.MnuEvalOff.Enabled = True Else Board.MnuEvalOff.Enabled = False
If Board.MnuEvalOn.Checked = False Then Board.MnuEvalOn.Checked = True Else Board.MnuEvalOn.Checked = False
If Board.MnuEvalOff.Checked = False Then Board.MnuEvalOff.Checked = True Else Board.MnuEvalOff.Checked = False

End Sub

Sub SetGeneral()
If GeneralInfo = 0 Then Unload RulesHelp
GeneralInfo = 1
For Z = 0 To 17
    RulesHelp.Title(Z).Visible = False
Next Z
RulesHelp.Title(9).Visible = True
RulesHelp.CmdPiece.Visible = False
RulesHelp.Show
End Sub

Sub SetGrade()

Select Case Grade
    Case "Weak": Level = 1
    Case "LessWeak": Level = 5
End Select
If Grade = "LessWeak" Then
    Select Case Choice
        Case "Micro", "Mini": Level = 12
        Case "Judkin", "Whale", "Yari", "Tori", "HeianSho": Level = 7
        Case "Wa", "Chu", "Dai", "DaiDai", "Maka", "Tai": Level = 4
        Case "Tenjiku": Level = 3
    End Select
End If

End Sub

Sub SetGrafix()

Grafix(InitFile, InitRank) = NewGraf
Graphnum = Pieces(Abs(Squares(InitFile, InitRank))).Graphic
If (Squares(InitFile, InitRank) < 0 And Reverse = 0) Or (Squares(InitFile, InitRank) > 0 And Reverse = 1) Then Graphnum = Graphnum + (TotGraph / 2)
If Choice = "Tai" Then Board.showpic(NewGraf) = TaiPieces.Pix(Graphnum - 1) Else Board.showpic(NewGraf) = Board.Pix(Graphnum - 1)
If Reverse = 0 Then
    Board.showpic(NewGraf).Move XStart + ((InitFile - 1) * Pixels), 11 + ((InitRank - 1) * Pixels)
Else
    Board.showpic(NewGraf).Move XStart + ((BoardSizeX - InitFile) * Pixels), 11 + ((BoardSizeY - InitRank) * Pixels)
End If
Board.showpic(NewGraf).Visible = True

End Sub

Sub SetHandicap()
If Reduce <> 1 Then
    Board.Caption = "Select Handicap Pieces - (Press Right Mouse Button to Start Game)"
Else
    Board.Caption = "Select Pieces to Remove - (Press Right Mouse Button When Finished)"
End If
If Reduce <> 1 Then Handicap = 1
Board.BlackClock.Caption = "00:00:00"
Board.WhiteClock.Caption = "00:00:00"
Board.Timer1.Enabled = False
End Sub

Sub SetKings()

BlackPrince = 0: BlackKing = 1: BlackEmperor = 0
WhitePrince = 0: WhiteKing = 1: WhiteEmperor = 0
For GG = 1 To BoardSizeY
    For HH = 1 To BoardSizeX
        If Squares(HH, GG) = 1 Then BlackKing = 0: BlackKingX = HH: BlackKingY = GG
        If Squares(HH, GG) = -1 Then WhiteKing = 0: WhiteKingX = HH: WhiteKingY = GG
        If Squares(HH, GG) > 0 Then
            If Pieces(Abs(Squares(HH, GG))).Name = "Prince" Or Pieces(Abs(Squares(HH, GG))).Name = "Crown Prince" Then BlackPrince = BlackPrince + 1
            If Pieces(Abs(Squares(HH, GG))).Name = "Emperor" Then BlackEmperor = 1: BlackEmpX = HH: BlackEmpY = GG
        End If
        If Squares(HH, GG) < 0 Then
            If Pieces(Abs(Squares(HH, GG))).Name = "Prince" Or Pieces(Abs(Squares(HH, GG))).Name = "Crown Prince" Then WhitePrince = WhitePrince + 1
            If Pieces(Abs(Squares(HH, GG))).Name = "Emperor" Then WhiteEmperor = 1: WhiteEmpX = HH: WhiteEmpY = GG
        End If
    Next HH
Next GG
End Sub

Sub SetLastMove()

If Board.MnuShowLastOn.Enabled = False Then Board.MnuShowLastOn.Enabled = True Else Board.MnuShowLastOn.Enabled = False
If Board.MnuShowLastOff.Enabled = False Then Board.MnuShowLastOff.Enabled = True Else Board.MnuShowLastOff.Enabled = False
If Board.MnuShowLastOn.Checked = False Then Board.MnuShowLastOn.Checked = True Else Board.MnuShowLastOn.Checked = False
If Board.MnuShowLastOff.Checked = False Then Board.MnuShowLastOff.Checked = True Else Board.MnuShowLastOff.Checked = False
End Sub

Sub SetLionHawk()
    If Board.MnuLVer1.Enabled = False Then Board.MnuLVer1.Enabled = True Else Board.MnuLVer1.Enabled = False
    If Board.MnuLVer2.Enabled = False Then Board.MnuLVer2.Enabled = True Else Board.MnuLVer2.Enabled = False
    If Board.MnuLVer1.Checked = False Then Board.MnuLVer1.Checked = True Else Board.MnuLVer1.Checked = False
    If Board.MnuLVer2.Checked = False Then Board.MnuLVer2.Checked = True Else Board.MnuLVer2.Checked = False
End Sub

Sub SetPieces()
   
   Randomize
   XA = 0: GameOver = 0: LegalMoves = 0: OldThreat = "None"
   If Reload <> 1 Then ConfigLoad Else ConfigLoad2
   Reload = 1: Influence = 0: CompMove = 0: Evaluate = 0
   LionPiece = -1: CheckTest = 0: Checked = 0
   Datafile = Direct + "\Data\" + Choice + ".dat"
   Turn = "Black": LionPiece = -1: WhiteKing = 0: BlackKing = 0: WhitePrince = 0: BlackPrince = 0: RealLion = 0
   HandGame = 0: WhiteLion = 0: BlackLion = 0: WhiteEmperor = 0: BlackEmperor = 0: Taken = 0: Mate = 0
   CMove$ = "": TurnCount = 0: EndTurn = 0: MoveCount = 0
   Board.LastMove.Caption = "": Board.NextMove.Caption = "Black to Move"
   If Reverse <> 1 Then Reverse = 0
   XStart = 110
   If Choice = "Tenjiku" Then Computer = "None"
   If Choice = "Chu" Or Choice = "Dai" Or Choice = "DaiDai" Or Choice = "Maka" Or Choice = "Tai" Then Grade = "Weak": SetDifficulty
   If Choice = "Whale" Or Choice = "Judkin" Then XStart = 140
   If Choice = "Mini" Then XStart = 170
   If Choice = "Micro" Then XStart = 200
   If Choice = "Yari" Then XStart = 157
   ReDim ShortScore(4000)
   ReDim Score(4000)
   ReDim Captures(4000)

   Open Datafile For Input As #1
     
     '  load general game data

     Input #1, Cap, Boardbmp, Drop, Boardsize, Prom, PromDotY
     Input #1, XCorner, YCorner, Pixels, Totpiece, PieceNum, TotGraph
     BoardSizeX = Boardsize: BoardSizeY = Boardsize
     If Choice = "HShogi" Then BoardSizeY = 8
     If Choice = "Micro" Then BoardSizeY = 5
     If Choice = "Yari" Then BoardSizeY = 9: BoardSizeX = 7
     If Loading = 1 Then
         Input #2, Drop, MoveCount, Turn, Notate, SeeMove, TurnCount, WhiteKing, BlackKing
         Input #2, WhiteLion, BlackLion, WhitePrince, BlackPrince, WhiteEmperor, BlackEmperor, LastGo$
         Input #2, WhiteTime$, BlackTime$, HandGame, Reverse
         EndTurn = TurnCount
         Board.LastMove.Caption = LastGo$
         Board.WhiteClock.Caption = WhiteTime$
         Board.BlackClock.Caption = BlackTime$
         If GameOver = 1 Then
            Board.NextMove.Caption = "Game Ended"
         Else
            If Turn = "White" Then Board.NextMove.Caption = "White to Move"
         End If
         For W = 0 To TurnCount
             Input #2, Score(W).Caption, Score(W).IDStart, Score(W).IDEnd, Score(W).PosStart, Score(W).PosEnd
             Input #2, Captures(W).number
             For V = 1 To Captures(W).number
                 Input #2, Captures(W).Positions(V)
                 Input #2, Captures(W).PieceNum(V)
             Next V
         Next W
     Else
         Board.MnuHandicap.Enabled = True
     End If
     ReDim Pieces(1 To PieceNum / 2) As Piece
     ReDim TestBoard(BoardSizeX, BoardSizeY) As Integer
     ReDim Grafix(BoardSizeX, BoardSizeY) As Integer
     ReDim Squares(BoardSizeX, BoardSizeY) As Integer
     ReDim Legal(BoardSizeX, BoardSizeY) As Integer
     ReDim OldLegal(BoardSizeX, BoardSizeY) As Integer
     ReDim AreaOK(BoardSizeX, BoardSizeY) As Integer
     ReDim Camps(BoardSizeX, BoardSizeY) As Integer
     ReDim Comp(BoardSizeX, BoardSizeY) As Integer
     ReDim Clearing(200) As Empty
     ReDim BanMap(BoardSizeX, BoardSizeY) As Map
     ReDim BackMap(BoardSizeX, BoardSizeY) As Map
     ReDim Attacker(BoardSizeX, BoardSizeY) As Integer
     ReDim OldAttack(BoardSizeX, BoardSizeY) As Integer
     ReDim PieceMask(6, Pixels)
     ReDim CompLegal(2000) As LegalList
     ReDim KingTally(2000) As Long
     ReDim LowBlack(BoardSizeX, BoardSizeY) As Integer
     ReDim LowWhite(BoardSizeX, BoardSizeY) As Integer
     If Choice = "Wa" And Loading <> 1 Then WaDrop
     If Choice = "Wa" And Drop = 1 Then Boardbmp = "WaBoard2.bmp"
     Board.Picture = LoadPicture(Direct + "\Data\" + Boardbmp)
     Board.Caption = Cap
     
     ' load piece data

     For I = 1 To PieceNum / 2
        Input #1, Pieces(I).number, Pieces(I).Name
        Input #1, Pieces(I).sname, Pieces(I).Value
        Input #1, Pieces(I).PrValue, Pieces(I).Promotes, Pieces(I).Graphic
        Input #1, Pieces(I).PrGraphic
        For J = 1 To 8
            Input #1, Pieces(I).Moves(J)
        Next J
        Input #1, Pieces(I).special
        Input #1, Pieces(I).Mask
        Input #1, Pieces(I).Range
     Next I

     ' load board data

     Count = 0: M = 0
     For J = 1 To BoardSizeY
        For I = 1 To BoardSizeX
            Input #1, Squares(I, J)
            If Loading = 1 Then Input #2, Squares(I, J)
            Grafix(I, J) = -1
            If Squares(I, J) <> 0 Then
                Graphnum = Pieces(Abs(Squares(I, J))).Graphic
                If (Squares(I, J) < 0 And Reverse = 0) Or (Squares(I, J) > 0 And Reverse = 1) Then Graphnum = Graphnum + (TotGraph / 2)
                If Choice = "Tai" Then Board.showpic(Count) = TaiPieces.Pix(Graphnum - 1) Else Board.showpic(Count) = Board.Pix(Graphnum - 1)
                If Reverse = 0 Then
                    Board.showpic(Count).Move XStart + ((I - 1) * Pixels), 11 + ((J - 1) * Pixels)
                Else
                    Board.showpic(Count).Move XStart + ((BoardSizeX - I) * Pixels), 11 + ((BoardSizeY - J) * Pixels)
                End If
                Board.showpic(Count).Visible = True
                Grafix(I, J) = Count
                Count = Count + 1
            End If
        Next I
     Next J

'Load Drop Data

  If Drop = 1 Or Choice = "Wa" Then
     If Loading = 1 Then
         For K = Count To Totpiece
             Board.showpic(K).Visible = False
         Next K
     End If
     Input #1, Capture
     ReDim CapRef(Capture * 2) As Integer
     ReDim InHand(Capture * 2) As Integer
     ReDim CompHeld(Capture * 2) As Integer
     ReDim OldHand(Capture * 2) As Integer
     For I = 1 To Capture
        Input #1, CapRef(I)
        CapRef(I + Capture) = 0 - CapRef(I)
     Next I
     If Reverse = 0 Then
         Board.White.Picture = LoadPicture(Direct + "\Data\" + "WhiteDn.bmp")
         Board.Black.Picture = LoadPicture(Direct + "\Data\" + "BlackUp.bmp")
     Else
         Board.White.Picture = LoadPicture(Direct + "\Data\" + "WhiteUp.bmp")
         Board.Black.Picture = LoadPicture(Direct + "\Data\" + "BlackDn.bmp")
         For I = 1 To Capture * 2
            CapRef(I) = 0 - CapRef(I)
         Next I
     End If
     For I = 1 To Capture * 2
        InHand(I) = 0
        If Loading = 1 Then Input #2, InHand(I)
        Graphnum = Pieces(Abs(CapRef(I))).Graphic
        If I > Capture Then Graphnum = Graphnum + (TotGraph / 2)
        Board.HandPic(I) = Board.Pix(Graphnum - 1)
        Board.HandPic(I).Visible = False
        Board.Held(I).Caption = ""
        If Loading = 1 And InHand(I) > 0 Then Board.HandPic(I).Visible = True
        If Loading = 1 And InHand(I) > 1 Then Board.Held(I).Caption = InHand(I)
        If Choice <> "Wa" And Choice <> "Micro" Then
            If I <= Capture Then
                X = 629 - Pixels
                Y = 11 + (I - 1) * Pixels
            Else
                X = 10
                Y = 11 + (Capture - I + Capture) * Pixels
            End If
            Board.HandPic(I).Move X, Y
        End If
        If Choice = "Wa" Or Choice = "Micro" Then
            If I <= Capture Then
                If I <= Capture / 2 Then
                    X = 629 - Pixels
                    Y = 11 + (I - 1) * Pixels
                Else
                    X = 629 - (Pixels * 2)
                    Y = 11 + (I - (Capture / 2) - 1) * Pixels
                End If
            Else
                If I <= Capture * 1.5 Then
                    X = 10
                    Y = 11 + (Capture - I + (Capture / 2)) * Pixels
                Else
                    X = 10 + Pixels
                    Y = 11 + (Capture - (I - (Capture / 2)) + (Capture / 2)) * Pixels
                End If
            End If
        Board.HandPic(I).Move X, Y
        End If
     Next I
  End If
  Input #1, PieceSizes
  For J = 1 To PieceSizes
      For K = 1 To Pixels
          Input #1, PieceMask(J, K)
      Next K
  Next J
  Close #1
  SetKings
  NotSet
  Notation
  If Board.WindowState <> 2 Then
      If Choice <> "Tai" Then
        Board.Left = (Screen.Width / 2) - 4860
        Board.Top = (Screen.Height / 2) - 3650
      Else
        Board.Left = (Screen.Width / 2) - 6075
        Board.Top = (Screen.Height / 2) - 4562
      End If
  End If
  If (Display = 640 Or Choice = "Tai") And NewGame <> 1 Then
    Board.Left = 5
    Board.Top = 5
    Board.WindowState = 2
  Else
    Board.WindowState = 0
  End If
  If Choice = "Tai" Then Board.WindowState = 2
  If Loading <> 1 And Timing <> 1 Then ClocksOn
  If Board.WhiteClock.Caption <> "00:00:00" Or Board.BlackClock.Caption <> "00:00:00" Then Board.Timer1.Enabled = True
  If Timing = 1 Then ClocksOff
  If Choice = "Tai" Or Choice = "Maka" Then
    If Computer = "White" Or Computer = "Black" Or Computer = "Both" Then CompTeach Else NoCompTeach
  End If
  Board.MnuBest.Visible = False
  Board.Show
  Start.MousePointer = 0
  Start.Hide
  If Computer = "White" Or Computer = "Black" Then
    Board.MnuSwitch.Enabled = True
    Board.PieceID.Caption = "Computer plays " + Computer: Notice = 1
  Else
    Board.MnuSwitch.Enabled = False
  End If
  If Computer = Turn Or Computer = "Both" Then CompMain
End Sub

Sub SetRules()
If GeneralInfo = 1 Then Unload RulesHelp
GeneralInfo = 0
For Z = 0 To 17
    RulesHelp.Title(Z).Visible = False
Next Z
If GameNo < 10 Then RulesHelp.Title(GameNo - 1).Visible = True Else RulesHelp.Title(GameNo).Visible = True
RulesHelp.CmdPiece.Visible = True
RulesHelp.Show
End Sub

Sub SetSuggest()
Suggest = 1
OldSeeMove = SeeMove
OldComputer = Computer
Computer = Turn
Board.Caption = "The Computer suggests....": Notice = 5
RealLevel = Level: Level = 1
CompMain
Level = RealLevel
LegalMoves = 0

End Sub

Sub SetTeach()
    If Board.MnuVer1.Enabled = False Then Board.MnuVer1.Enabled = True Else Board.MnuVer1.Enabled = False
    If Board.MnuVer2.Enabled = False Then Board.MnuVer2.Enabled = True Else Board.MnuVer2.Enabled = False
    If Board.MnuVer1.Checked = False Then Board.MnuVer1.Checked = True Else Board.MnuVer1.Checked = False
    If Board.MnuVer2.Checked = False Then Board.MnuVer2.Checked = True Else Board.MnuVer2.Checked = False
End Sub

Sub SetThreat()
    If Board.MnuThreatOn.Enabled = False Then Board.MnuThreatOn.Enabled = True Else Board.MnuThreatOn.Enabled = False
    If Board.MnuThreatOff.Enabled = False Then Board.MnuThreatOff.Enabled = True Else Board.MnuThreatOff.Enabled = False
    If Board.MnuThreatOn.Checked = False Then Board.MnuThreatOn.Checked = True Else Board.MnuThreatOn.Checked = False
    If Board.MnuThreatOn.Checked = False Then Board.MnuThreatOff.Checked = True Else Board.MnuThreatOff.Checked = False
    If SeeMove = 1 And OldThreat <> "On" And OldThreat <> "Off" Then
        If Board.MnuThreatOff.Enabled = False Then Board.PieceID.Caption = "Show Influence or Threats Off"
    End If
    If OldThreat <> "On" And OldThreat <> "Off" Then
        If Board.MnuThreatOff.Enabled = True Then Board.PieceID.Caption = "Show Influence or Threats On"
    End If
    Notice = 1
End Sub

Sub SetWhitePlayer()

If Board.MnuWhitePlayer.Enabled = False Then Board.MnuWhitePlayer.Enabled = True Else Board.MnuWhitePlayer.Enabled = False
If Board.MnuWhiteComp.Enabled = False Then Board.MnuWhiteComp.Enabled = True Else Board.MnuWhiteComp.Enabled = False
If Board.MnuWhitePlayer.Checked = False Then Board.MnuWhitePlayer.Checked = True Else Board.MnuWhitePlayer.Checked = False
If Board.MnuWhiteComp.Checked = False Then Board.MnuWhiteComp.Checked = True Else Board.MnuWhiteComp.Checked = False
If Choice = "Tai" Or Choice = "Maka" Then
    If Computer = "White" Or Computer = "Black" Or Computer = "Both" Then CompTeach Else NoCompTeach
End If
If Computer = "Both" Then CompVComp
End Sub

Sub ShowMove()

If GameOver = 1 Or Checked > 0 Then Exit Sub
If Squares(NewFile, NewRank) = 0 And (Range <> 1 Or Influence > 0) Then
    If Pieces(Abs(Squares(InitFile, InitRank))).special <> "T" Or M <> 1 Then
        If Pieces(Abs(Squares(InitFile, InitRank))).special = "T" Then Tetrarchs
        If Blocked <> 1 Then
            Legal(NewFile, NewRank) = 1
            Board.FillColor = &HFFFFFF
            If SeeMove = 1 Or CompMove = 1 Or Evaluate = 1 Then SeeFile = NewFile: SeeRank = NewRank: LookMove
            If Demon = 1 Then FireDemon
        End If
        Blocked = 0
    End If
    If Choice = "Tenjiku" Then CheckBurn
Else
    If Pieces(Abs(Squares(InitFile, InitRank))).special <> "T" Or M <> 1 Then Last = 1
    If Pieces(Abs(Squares(InitFile, InitRank))).special = "T" Then Tetrarchs
    If Blocked <> 1 Then
        If (Sgn(Squares(InitFile, InitRank)) <> Sgn(Squares(NewFile, NewRank)) Or Influence > 0) And Legal(NewFile, NewRank) <> 4 And Squares(NewFile, NewRank) <> 0 Then
            If Squares(NewFile, NewRank) <> 0 And Range = 1 Then TestStrength
            If Choice = "Chu" And Pieces(Abs(Squares(NewFile, NewRank))).Name = "Lion" And Pieces(Abs(Squares(InitFile, InitRank))).Name <> "Lion" Then
                NoLionCapture = 0
                If Turn = "Black" Then
                    If WhiteLion = 1 Then NoLionCapture = 1
                Else
                    If BlackLion = 1 Then NoLionCapture = 1
                End If
            End If
            If Weaker <> 1 And NoLionCapture <> 1 Then
                Board.FillColor = &HFF&
                Legal(NewFile, NewRank) = 1
                If SeeMove = 1 Then SeeFile = NewFile: SeeRank = NewRank: LookMove
                If Demon = 1 Then FireDemon
                If Choice = "Tenjiku" Then CheckBurn
            End If
            NoLionCapture = 0
        End If
    End If
    Blocked = 0
End If
End Sub

Sub ShowProm()

If Computer <> Turn And Computer <> "Both" And Level <> 0 And GameOver <> 1 Then
If Selection <> 0 Or MovePiece = 1 Then
    EndSelect
Else
    If Handicap = 1 Or Reduce = 1 Then
        Board.Caption = Cap
        Handicap = 0: Reduce = 0
        Board.Timer1.Enabled = True
    Else
        If ClickPiece = 1 Then
            RightClick = 1
            Board.PieceID.Caption = ""
            Board.PieceID.ForeColor = &H8000&
            For K = 1 To BoardSizeY
                For L = 1 To BoardSizeX
                    If Grafix(L, K) = I Then
                        If Pieces(Abs(Squares(L, K))).Promotes > 0 And Pieces(Abs(Squares(L, K))).Name <> "Killer Whale" Then PromName = "Promotes to " + Pieces(Abs(Pieces(Abs(Squares(L, K))).Promotes)).Name Else PromName = "Does not promote"
                        If Pieces(Abs(Squares(L, K))).Name = "Porpoise" Then PromName = "Promotes to Killer Whale"
                        Board.PieceID.Caption = PromName
                        InitFile = L: InitRank = K
                        If SeeMove = 1 And Threat = "On" Then ActingPieces
                    End If
                Next L
            Next K
            ClickPiece = 0
        Else
            FormActing
        End If
    End If
End If
End If
End Sub

Sub SingleStep()
Last = 0: M = 0: NewFile = InitFile: NewRank = InitRank
While NewFile + FileInc > 0 And NewFile + FileInc <= BoardSizeX And NewRank + RankInc > 0 And NewRank + RankInc <= BoardSizeY And M < MoveTest And Last = 0
    NewFile = NewFile + FileInc
    NewRank = NewRank + RankInc
    M = M + 1
    ShowMove
    If NewRank <= BoardSizeY And NewRank > 0 And NewFile > 0 And NewFile <= BoardSizeX Then
        If Range = 1 And Squares(NewFile, NewRank) <> 0 Then TestStrength
        If Range = 1 And Weaker = 0 Then Last = 0
    End If
    If Hook = 1 And Last <> 1 Then HookMove
Wend
Range = 0: Weaker = 0: Hook = 0
End Sub

Sub SpecialMove()
Select Case Pieces(Abs(Squares(InitFile, InitRank))).special
    Case "L": If LionPiece = I Then Lion2 Else Lion
    Case "T": Igui
    Case "D": Area = 2: P = InitFile: N = InitRank: AreaMove
    Case "F": Area = 3: P = InitFile: N = InitRank: AreaMove
    'Case "E":  Emperor
End Select
If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Vice General" Then
    Area = 3: N = InitRank: P = InitFile
    AreaMove
End If
End Sub

Sub SquareReplace()
If MovePiece = 1 Then
    Move2
Else
K = 1
Do
    L = 1
    Do
        If Grafix(L, K) = I Then
            InitFile = L
            InitRank = K
            Found = 1
       End If
       L = L + 1
    Loop Until L > BoardSizeX Or Found = 1
    K = K + 1
Loop Until K > BoardSizeY Or Found = 1
Found = 0
Victim$ = Pieces(Abs(Squares(InitFile, InitRank))).Name
If Squares(InitFile, InitRank) > 0 And (Victim$ = "Prince" Or Victim$ = "Crown Prince") Then BlackPrince = BlackPrince - 1
If Squares(InitFile, InitRank) < 0 And (Victim$ = "Prince" Or Victim$ = "Crown Prince") Then WhitePrince = WhitePrince - 1
Squares(InitFile, InitRank) = Selection
Board.showpic(Grafix(InitFile, InitRank)).Visible = False
Board.showpic(Grafix(InitFile, InitRank)).Move 0, 0
NewGraf = Grafix(InitFile, InitRank)
SetGrafix
Reduce = 0: MovePiece = 0
End If
End Sub

Sub StartUp()
Select Case Choice
  Case "Micro": GameName = "Micro": GameNo = 14: Load Micro: Set Board = Micro
  Case "Whale": GameName = "Whale": GameNo = 15: Load Whale: Set Board = Whale
  Case "Shogi": GameName = "": GameNo = 2: Load Shogi: Set Board = Shogi
  Case "Tori": GameName = "Bird": GameNo = 1: Load Tori: Set Board = Tori
  Case "Sho": GameName = "Little": GameNo = 11: Load Shogi: Set Board = Shogi
  Case "Wa": GameName = "Wa": GameNo = 3: Load Wa: Set Board = Wa
  Case "Chu": GameName = "Middle": GameNo = 4: Load Chu: Set Board = Chu
  Case "Dai": GameName = "Great": GameNo = 5: Load Dai: Set Board = Dai
  Case "Tenjiku": GameName = "Exotic": GameNo = 6: Load Tenjiku: Set Board = Tenjiku
  Case "DaiDai": GameName = "Great Great": GameNo = 7: Load DaiDai: Set Board = DaiDai
  Case "Maka": GameName = "Ultra Great Great": GameNo = 8: Load Maka: Set Board = Maka
  Case "Tai": GameName = "Grand": GameNo = 9: Load Tai: Set Board = Tai
  Case "HShogi": GameName = "Early": GameNo = 12: Load HeianSho: Set Board = HeianSho
  Case "Heian": GameName = "Early Great": GameNo = 10: Load Heian: Set Board = Heian
  Case "Mini": GameName = "Mini": GameNo = 13: Load Mini: Set Board = Mini
  Case "Yari": GameName = "Yari": GameNo = 16: Load Yari: Set Board = Yari
  Case "Judkin": GameName = "Judkin's": GameNo = 17: Load Judkin: Set Board = Judkin
End Select
SetPieces
If OldChoice <> Choice Then
  Select Case OldChoice
    Case "Micro": Unload Micro
    Case "Whale": Unload Whale
    Case "Sho": Unload Shogi
    Case "Shogi": Unload Shogi
    Case "Tori": Unload Tori
    Case "Wa": Unload Wa
    Case "Chu": Unload Chu
    Case "Dai": Unload Dai
    Case "Tenjiku": Unload Tenjiku
    Case "DaiDai": Unload DaiDai
    Case "Maka": Unload Maka
    Case "Tai": Unload Tai: Unload TaiPieces
    Case "Heian": Unload Heian
    Case "HShogi": Unload HeianSho
    Case "Mini": Unload Mini
    Case "Yari": Unload Yari
    Case "Judkin": Unload Judkin
End Select
Else
    Board.MousePointer = 0
End If
End Sub

Sub SuggestMove()

SeeMove = OldSeeMove
Suggest = 0
Computer = OldComputer
Board.ForeColor = &HFF&
Board.FillStyle = 1
Board.DrawWidth = 2
Board.ForeColor = &HFFFFFF
If CompLegal(BestMove).StartFile <> 0 Then
    If Reverse = 0 Then
        Board.Line (XStart - 1 + ((CompLegal(BestMove).StartFile - 1) * Pixels), 10 + ((CompLegal(BestMove).StartRank - 1) * Pixels))-(XStart - 1 + (CompLegal(BestMove).StartFile * Pixels), 10 + (CompLegal(BestMove).StartRank * Pixels)), , B
    Else
        Board.Line (XStart - 1 + (BoardSizeX - CompLegal(BestMove).StartFile) * Pixels, 10 + ((BoardSizeY - CompLegal(BestMove).StartRank) * Pixels))-(XStart - 1 + ((BoardSizeX - CompLegal(BestMove).StartFile + 1) * Pixels), 10 + ((BoardSizeY - CompLegal(BestMove).StartRank + 1) * Pixels)), , B
    End If
Else
    For HH = 1 To Capture * 2
        If CapRef(HH) = CompLegal(BestMove).EndPiece Then II = HH
    Next HH
    If Choice <> "Wa" And Choice <> "Micro" Then
        If II <= Capture Then
            X = 629 - Pixels
            Y = 11 + (II - 1) * Pixels
        Else
            X = 10
            Y = 11 + (Capture - II + Capture) * Pixels
        End If
        Board.Line (X, Y)-(X + Pixels, Y + Pixels), , B
    End If
    If Choice = "Wa" Or Choice = "Micro" Then
    If II <= Capture Then
        If II <= Capture / 2 Then
            X = 629 - Pixels
            Y = 11 + (II - 1) * Pixels
        Else
            X = 629 - (Pixels * 2)
            Y = 11 + (II - (Capture / 2) - 1) * Pixels
        End If
    Else
        If II <= Capture * 1.5 Then
            X = 10
            Y = 11 + (Capture - II + (Capture / 2)) * Pixels
        Else
            X = 10 + Pixels
            Y = 11 + (Capture - (II - (Capture / 2)) + (Capture / 2)) * Pixels
        End If
    End If
    Board.Line (X, Y)-(X + Pixels, Y + Pixels), , B
End If
End If
Board.FillStyle = 0
Board.DrawWidth = 1
Board.ForeColor = &H0&
If Reverse = 0 Then
    Board.Circle (XStart + ((CompLegal(BestMove).EndFile - 1) * Pixels) + (Pixels / 2), 11 + ((CompLegal(BestMove).EndRank - 1) * Pixels) + (Pixels / 2)), Pixels / 4
Else
    Board.Circle (XStart + ((BoardSizeX - CompLegal(BestMove).EndFile) * Pixels) + (Pixels / 2), 11 + ((BoardSizeY - CompLegal(BestMove).EndRank) * Pixels) + (Pixels / 2)), Pixels / 4
End If
For MM = 1 To BoardSizeY
    For GG = 1 To BoardSizeX
        Squares(GG, MM) = Comp(GG, MM)
    Next GG
Next MM
ResetLegal
End Sub

Sub SwitchCompPlayer()

If LegalMoves = 0 Then
    If Computer = "White" Then
        Computer = "Black"
        Board.MnuWhitePlayer.Enabled = False: Board.MnuBlackPlayer.Enabled = True
        Board.MnuWhitePlayer.Checked = True:  Board.MnuBlackPlayer.Checked = False
        Board.MnuWhiteComp.Enabled = True: Board.MnuBlackComp.Enabled = False
        Board.MnuBlackComp.Checked = True: Board.MnuWhiteComp.Checked = False
        Board.PieceID.Caption = "Computer plays Black": Notice = 1
        If Turn = "Black" Then
            FirstSeeMove = SeeMove
            SeeMove = 1
            CompMain
            SeeMove = FirstSeeMove
        End If
    Else
        Computer = "White"
        Board.MnuWhitePlayer.Enabled = True: Board.MnuBlackPlayer.Enabled = False
        Board.MnuWhitePlayer.Checked = False:  Board.MnuBlackPlayer.Checked = True
        Board.MnuWhiteComp.Enabled = False: Board.MnuBlackComp.Enabled = True
        Board.MnuBlackComp.Checked = False: Board.MnuWhiteComp.Checked = True
        Board.PieceID.Caption = "Computer plays White": Notice = 1
        If Turn = "White" Then
            FirstSeeMove = SeeMove
            SeeMove = 1
            CompMain
            SeeMove = FirstSeeMove
        End If
    End If
End If
End Sub

Sub Take2()
If (LegalMoves = 0 Or Checked = 2) And LionPiece <> I And XA = 0 Then
If TurnCount > 0 Then
    GameOver = 0
    TurnCount = TurnCount - 1
    Location = Score(TurnCount).PosEnd
    If Location > 0 Then
        Rank = Int(Location / (BoardSizeX + 1))
        File = Location - (Rank * (BoardSizeX + 1))
        Squares(File, Rank) = Score(TurnCount).IDEnd
    End If
    Location = Score(TurnCount).PosStart
    If Location > 0 Then
        InitRank = Int(Location / (BoardSizeX + 1))
        InitFile = Location - (InitRank * (BoardSizeX + 1))
        Squares(InitFile, InitRank) = Score(TurnCount).IDStart
        If Squares(InitFile, InitRank) < 0 Then
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Emperor" Then WhiteEmpX = InitFile: WhiteEmpY = InitRank
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "King" Then WhiteKingX = InitFile: WhiteKingY = InitRank
        End If
        If Squares(InitFile, InitRank) > 0 Then
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Emperor" Then BlackEmpX = InitFile: BlackEmpY = InitRank
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "King" Then BlackKingX = InitFile: BlackKingY = InitRank
        End If
   End If
   If InitFile <> File Or InitRank <> Rank Then Squares(File, Rank) = 0
   If Score(TurnCount).IDEnd <> 0 Then
        If Score(TurnCount).PosStart = 0 Then
            CaptPiece = Score(TurnCount).IDEnd
            Squares(File, Rank) = 0
            AddHand3
        End If
    End If
    For V = 1 To Captures(TurnCount).number
        Location = Captures(TurnCount).Positions(V)
        InitRank = Int(Location / (BoardSizeX + 1))
        InitFile = Location - (InitRank * (BoardSizeX + 1))
        Squares(InitFile, InitRank) = Captures(TurnCount).PieceNum(V)
    Next V
    If Drop = 1 And Captures(TurnCount).number > 0 Then ReduceHand2
    If Turn = "Black" Then
        Turn = "White"
        Board.NextMove.Caption = "White to Move"
    Else
        MoveCount = MoveCount - 1: Turn = "Black"
        Board.NextMove.Caption = "Black to Move"
    End If
    If TurnCount = 0 Then
        Board.LastMove.Caption = ""
        If HandGame <> 1 And Turn = "Black" Then Board.MnuHandicap.Enabled = True
        If Turn = "Black" Then MoveCount = 0
    Else
        If Asc(Score(TurnCount).Caption) > 47 And Asc(Score(TurnCount).Caption) < 58 Then
            Board.LastMove.Caption = Score(TurnCount).Caption
        Else
            Board.LastMove.Caption = Format$(MoveCount) + ". " + Score(TurnCount).Caption
        End If
    End If
    Backwards = 1
End If
End If

End Sub

Sub TakeAll()

If LegalMoves = 0 Then
    Do While TurnCount > 0 Or (TurnCount > 1 And HandGame <> 1)
        Take2
    Loop
    Board.Caption = Cap
    RestoreGrafix
    SetKings
End If
End Sub

Sub TakeBack()
If (LegalMoves = 0 Or Checked = 2) And LionPiece <> I And XA = 0 Then
Notice = 0
Board.PieceID.Caption = ""
If Tabbing <> 1 Then Board.Caption = Cap
BugFix
If TurnCount < 1 Then
    Board.PieceID.ForeColor = &HFF&
    Board.PieceID.Caption = "No moves to take back!"
    Notice = 1
Else
    GameOver = 0
    TurnCount = TurnCount - 1
    Location = Score(TurnCount).PosEnd
    If Location > 0 Then
        Rank = Int(Location / (BoardSizeX + 1))
        File = Location - (Rank * (BoardSizeX + 1))
        Squares(File, Rank) = Score(TurnCount).IDEnd
    End If
    Location = Score(TurnCount).PosStart
    If Location > 0 Then
        InitRank = Int(Location / (BoardSizeX + 1))
        InitFile = Location - (InitRank * (BoardSizeX + 1))
        Squares(InitFile, InitRank) = Score(TurnCount).IDStart
        If Squares(InitFile, InitRank) < 0 Then
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Emperor" Then WhiteEmpX = InitFile: WhiteEmpY = InitRank
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "King" Then WhiteKingX = InitFile: WhiteKingY = InitRank
        End If
        If Squares(InitFile, InitRank) > 0 Then
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Emperor" Then BlackEmpX = InitFile: BlackEmpY = InitRank
            If Pieces(Abs(Squares(InitFile, InitRank))).Name = "King" Then BlackKingX = InitFile: BlackKingY = InitRank
        End If
   End If
    If InitFile <> File Or InitRank <> Rank Then Squares(File, Rank) = 0
    If Score(TurnCount).IDEnd = 0 Then
        NewGraf = 0
        Do While Board.showpic(NewGraf).Visible = True
            NewGraf = NewGraf + 1
        Loop
        SetGrafix
    Else
        NewGraf = Grafix(File, Rank)
        Grafix(File, Rank) = -1
        Board.showpic(NewGraf).Visible = False
        Board.showpic(NewGraf).Move 0, 0
        If Score(TurnCount).PosStart > 0 Then
            SetGrafix
        Else
            CaptPiece = Score(TurnCount).IDEnd
            Squares(File, Rank) = 0
            AddHand
        End If
    End If
    For V = 1 To Captures(TurnCount).number
        Location = Captures(TurnCount).Positions(V)
        InitRank = Int(Location / (BoardSizeX + 1))
        InitFile = Location - (InitRank * (BoardSizeX + 1))
        Squares(InitFile, InitRank) = Captures(TurnCount).PieceNum(V)
        NewGraf = 0
        Do While Board.showpic(NewGraf).Visible = True
            NewGraf = NewGraf + 1
        Loop
        SetGrafix
    Next V
    If Drop = 1 And Captures(TurnCount).number > 0 Then ReduceHand
    If Turn = "Black" Then
        Turn = "White"
        Board.NextMove.Caption = "White to Move"
    Else
        MoveCount = MoveCount - 1: Turn = "Black"
        Board.NextMove.Caption = "Black to Move"
    End If
    If TurnCount = 0 Then
        Board.LastMove.Caption = ""
        If HandGame <> 1 And Turn = "Black" Then Board.MnuHandicap.Enabled = True
        If Turn = "Black" Then MoveCount = 0
    Else
        If Asc(Score(TurnCount).Caption) > 47 And Asc(Score(TurnCount).Caption) < 58 Then
            Board.LastMove.Caption = Score(TurnCount).Caption
        Else
            Board.LastMove.Caption = Format$(MoveCount) + ". " + Score(TurnCount).Caption
        End If
    End If
    Backwards = 1
    SetKings
    If TurnCount > 0 Then
        Location = Score(TurnCount - 1).PosEnd
        If Location > 0 Then
            Rank = Int(Location / (BoardSizeX + 1))
            File = Location - (Rank * (BoardSizeX + 1))
        End If
        LastPieceX = File: LastPieceY = Rank
    Else
        LastPieceX = -1: LastPieceY = -1
    End If
    If Turn = Computer And Tabbing <> 1 Then
        If TurnCount > 0 Then
            TakeBack
        Else
            FirstSeeMove = SeeMove
            SeeMove = 1
            CompMain
        End If
    End If
    If Tabbing = 1 Then
        If Computer = "Black" Or Computer = "White" Then
            Board.Caption = "Move Taken Back (" + Str$(TurnCount) + " of" + Str$(EndTurn) + " ) : Press [ESC] to continue play."
        Else
            Board.Caption = "Move Taken Back (" + Str$(TurnCount) + " of" + Str$(EndTurn) + " )"
        End If
    End If
End If
            
End If
End Sub

Sub TeachingKing()
For Y = InitRank - 3 To InitRank + 3
    For X = InitFile - 3 To InitFile + 3
        If X > 0 And X <= BoardSizeX And Y > 0 And Y <= BoardSizeY Then
            If Squares(X, Y) = 0 Or Sgn(Squares(X, Y)) <> Sgn(Squares(InitFile, InitRank)) Then
                If Abs(Y - InitRank) <= 1 And Abs(X - InitFile) <= 1 Then
                    Board.FillColor = &H800080
                    Legal(X, Y) = 6
                 Else
                    If Abs(Y - InitRank) = 3 Or Abs(X - InitFile) = 3 Then
                        Board.FillColor = &HFFFF00
                        Legal(X, Y) = 1
                    Else
                        Board.FillColor = &HFF0000
                        Legal(X, Y) = 2
                    End If
                End If
                If SeeMove = 1 Then SeeFile = X: SeeRank = Y: LookMove
            End If
        End If
    Next X
Next Y
End Sub

Sub TenjikuScore1()
CD = Len(FirstScore)
For AB = 1 To CD
    If Mid(FirstScore, AB, 1) = " " Or Mid(FirstScore, AB, 1) = Chr$(10) Or Mid(FirstScore, AB, 1) = Chr$(13) Then
        FirstScore = Left(FirstScore, AB - 1) + Right(FirstScore, Len(FirstScore) - AB)
    End If
Next AB
End Sub

Sub TenjikuScore2()
CD = Len(SecondScore)
For AB = 1 To CD
    If Mid(SecondScore, AB, 1) = " " Or Mid(SecondScore, AB, 1) = Chr$(10) Or Mid(SecondScore, AB, 1) = Chr$(13) Then
        FirstScore = Left(SecondScore, AB - 1) + Right(SecondScore, Len(SecondScore) - AB)
    End If
Next AB
End Sub

Sub Territory()


If (Threat = "On" And Tilde = 0) Or (Tilde = 1 And LegalMoves = 0) Then
    If Tilde = 1 Then
        OldSeeMove = SeeMove
        SeeMove = 1
    End If
    If Tilde <> 1 Then GetSquare Else InitFile = 1
    If InitFile > 0 Then
        Influence = 2
        For AB = 1 To BoardSizeY
            For CD = 1 To BoardSizeX
                If Squares(CD, AB) <> 0 Then
                    InitFile = CD: InitRank = AB
                    Validate
                End If
            Next CD
        Next AB
        DisplayTerritory
        Influence = 0
    End If
    If Tilde = 1 Then SeeMove = OldSeeMove
End If

End Sub


Sub TestAhead()

' Find Legal Moves

For AA = 1 To BoardSizeY
    For BB = 1 To BoardSizeX
        Squares(BB, AA) = Comp(BB, AA)
    Next BB
Next AA
CompMove = 1: LegalMoves = 0
For YZ = 1 To BoardSizeY
    For VX = 1 To BoardSizeX
    If Turn = "White" Then
        If Squares(VX, YZ) < 0 Then
        InitFile = VX: InitRank = YZ
        I = Grafix(VX, YZ)
        Validate
        End If
    Else
        If Squares(VX, YZ) > 0 Then
        InitFile = VX: InitRank = YZ
        I = Grafix(VX, YZ)
        Validate
        End If
    End If
    Next VX
DoEvents
Next YZ

' Find Legal Drops

If Drop = 1 Then
    If (Turn = "Black" And Reverse = 0) Or (Turn = "White" And Reverse = 1) Then
    For TU = 1 To Capture
        ResetLegal
        If InHand(TU) > 0 Then
        I = TU: InitFile = 0: InitRank = 0
        HeldValid
        DoEvents
        End If
    Next TU
    Else
    For TU = Capture + 1 To Capture * 2
        If InHand(TU) > 0 Then
        ResetLegal
        I = TU: InitFile = 0: InitRank = 0
        HeldValid
        DoEvents
        End If
    Next TU
    End If
End If
ConsiderMove
Evaluate = 0: CompMove = 0: Influence = 0: EndMove = 0

End Sub

Sub TestDrop()

For DD = 1 To Capture * 2
    If CompLegal(BestMove).StartPiece = CapRef(DD) Then I = DD
Next DD
Legal(CompLegal(BestMove).EndFile, CompLegal(BestMove).EndRank) = 1

End Sub

Sub TestOther()

A$ = Pieces(Abs(Score(TurnCount).IDStart)).Name
If A$ <> "Pawn" And A$ <> "Sparrow" And A$ <> "Sparrow Pawn" And A$ <> "Swallow" And A$ <> "Dolphin" Then
    OriginalRank = Rank: OriginalFile = File
    OldSeeMove = SeeMove: SeeMove = 0
    OriginalPiece = Squares(File, Rank): Squares(File, Rank) = 0
    Location = Score(TurnCount).PosStart
    InitRank = Int(Location / (BoardSizeX + 1))
    InitFile = Location - (InitRank * (BoardSizeX + 1))
    Squares(InitFile, InitRank) = Score(TurnCount).IDStart
    InitFile = FirstFile: InitRank = FirstRank
    Validate
    Rank = OriginalRank: File = OriginalFile
    Location = Score(TurnCount).PosStart
    InitRank = Int(Location / (BoardSizeX + 1))
    InitFile = Location - (InitRank * (BoardSizeX + 1))
    Squares(InitFile, InitRank) = 0: Squares(File, Rank) = OriginalPiece
    SeeMove = OldSeeMove
    If Legal(File, Rank) > 0 Then Testing123 = 1 Else Testing123 = 0
End If
End Sub

Sub TestStrength()
Weaker = 0
If Pieces(Abs(Squares(NewFile, NewRank))).special = "G" Or Pieces(Abs(Squares(NewFile, NewRank))).special = "C" Then
    If Pieces(Abs(Squares(InitFile, InitRank))).Value <= Pieces(Abs(Squares(NewFile, NewRank))).Value Or Pieces(Abs(Squares(InitFile, InitRank))).Name = "Rook General" Then
          Weaker = 1
    End If
End If
End Sub

Sub Tetrarchs()

If InitFile < BoardSizeX Then
If FileInc = 1 And RankInc = 0 And M = 3 And Legal(InitFile + 1, InitRank) = 4 Then Blocked = 1
End If
If InitFile > 1 Then
If FileInc = -1 And RankInc = 0 And M = 3 And Legal(InitFile - 1, InitRank) = 4 Then Blocked = 1
End If
End Sub

Sub TextScore()
On Error Resume Next
Board.CMDiagram.DialogTitle = "Create Text Score"
Board.CMDiagram.Flags = &H400& Or &H800& Or &H4&
Board.CMDiagram.Action = 2
If Err = 32755 Then Exit Sub
Saved$ = Board.CMDiagram.FileName

Open Saved$ For Output As #3
If GameName <> "" Then
    Print #3, GameName; " Shogi"
    For I = 1 To Len(GameName) + 6
    Print #3, "=";
    Next I
Print #3,
End If
Print #3, SaveTitle$
K = 0
For W = 1 To TurnCount Step 2
    K = K + 1
    FirstScore = Score(W).Caption
    SecondScore = Score(W + 1).Caption
    Board.Caption = InStr(FirstScore, " ")
    If InStr(FirstScore, Chr$(13)) > 0 Then TenjikuScore1
    If InStr(SecondScore, Chr$(13)) > 0 Then TenjikuScore2
    If HandGame = 1 And W = 1 Then
    Print #3, "1. -  " + SecondScore + "  ";
    Else
    Print #3, K + "." + FirstScore + " " + SecondScore + "  ";
    End If
Next W
Close #3
Board.Caption = "Score text file " + Board.CMDiagram.FileName + " created.": Notice = 1
End Sub

Sub TooSmall()
Response% = MsgBox("A screen size of at least 800x600 is required to play this variant. You should use Windows 'Setup' to change your screen size before attempting to play Tai Shogi.", 0, "Tai Shogi (Grand Shogi)")
Start.Game(10).Enabled = False
Start.Game(10).Value = False
Start.Game(0).Value = True
Start.MousePointer = 0
End Sub

Sub TwoKings()
For K = Rank - 1 To Rank + 1
    For L = File - 1 To File + 1
        If L > 0 And L <= BoardSizeX And K > 0 And K <= BoardSizeY Then
            If (K <> Rank Or L <> File) Then
                If Abs(Squares(L, K)) = 1 Then
                    If Squares(L, K) = 1 Then Turn2 = "White" Else Turn2 = "Black"
                    Response% = MsgBox("You can't leave your " + Pieces(Abs(Squares(File, Rank))).Name + " in Check! ", 0, Turn2)
                    Checked = 2
                End If
            End If
        End If
    Next L
Next K

End Sub

Sub UnPromote()
If Computer <> Turn And Computer <> "Both" Then
DoubleProm = 0
If AutoPromote = 1 And ForceProm <> 1 Then
    If (Score(TurnCount - 1).IDStart <> Score(TurnCount - 1).IDEnd) And (Score(TurnCount - 1).IDEnd <> 0) Then
        For K = 1 To BoardSizeY
            For L = 1 To BoardSizeX
                If Grafix(L, K) = I Then
                    Location = Score(TurnCount - 1).PosEnd
                    Rank = Int(Location / (BoardSizeX + 1))
                    File = Location - (Rank * (BoardSizeX + 1))
                    If L = File And K = Rank Then
                        DoubleProm = 1
                        Squares(L, K) = Score(TurnCount - 1).IDStart
                        Score(TurnCount - 1).IDEnd = Score(TurnCount - 1).IDStart
                        Graphnum = Pieces(Abs(Squares(L, K))).Graphic
                        If (Squares(L, K) < 0 And Reverse = 0) Or (Squares(L, K) > 0 And Reverse = 1) Then Graphnum = Graphnum + (TotGraph / 2)
                        If Choice = "Tai" Then Board.showpic(I) = TaiPieces.Pix(Graphnum - 1) Else Board.showpic(I) = Board.Pix(Graphnum - 1)
                        Score(TurnCount).Caption = Left(Score(TurnCount).Caption, Len(Score(TurnCount).Caption) - 1) + "="
                        ShortScore(TurnCount) = Score(TurnCount).Caption
                        Board.LastMove.Caption = Format$(MoveCount) + ". " + ShortScore(TurnCount)
                    End If
                End If
            Next L
        Next K
    End If
End If
If DoubleProm = 0 Then LionIgui
End If
End Sub

Sub Validate()

If Squares(InitFile, InitRank) <> 0 Then
    If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Dolphin" Then DolphinMove
    SpecPower$ = Pieces(Abs(Squares(InitFile, InitRank))).special
    If SpecPower$ = "F" Then Demon = 1 Else Demon = 0
    If SpecPower$ <> "" And SpecPower$ <> "L" Then SpecialMove
    If SpecPower$ <> "L" And D <> 0 And LionPiece = I And Pieces(Abs(Squares(InitFile, InitRank))).Name <> "Teaching King" Then
        LionPower2
    Else
        If LionPiece <> I Then
            For N = 1 To 8
                Select Case N
                    Case 1: FileInc = 0: RankInc = -1
                    Case 2: FileInc = 0: RankInc = 1
                    Case 3: FileInc = -1: RankInc = 0
                    Case 4: FileInc = 1: RankInc = 0
                    Case 5: FileInc = -1: RankInc = -1
                    Case 6: FileInc = 1: RankInc = -1
                    Case 7: FileInc = -1: RankInc = 1
                    Case 8: FileInc = 1: RankInc = 1
                End Select
                If Squares(InitFile, InitRank) < 0 Then
                    FileInc = 0 - FileInc
                    RankInc = 0 - RankInc
                End If
                MoveData = Pieces(Abs(Squares(InitFile, InitRank))).Moves(N)
                MoveTest = ((MoveData / 128) - Int(MoveData / 128)) * 128
                If MoveTest > 0 Then SingleStep
                MoveTest = ((MoveData / 256) - Int(MoveData / 256)) * 256
                If MoveTest >= 128 Then Jumping
                MoveTest = ((MoveData / 512) - Int(MoveData / 512)) * 512
                If MoveTest >= 256 Then RangeJump
                MoveTest = ((MoveData / 1024) - Int(MoveData / 1024)) * 1024
                If MoveTest >= 512 Then LionPower
                MoveTest = ((MoveData / 2048) - Int(MoveData / 2048)) * 2048
                If MoveTest >= 1024 Then KnightJump
                If MoveData >= 2048 Then
                    Hook = 1
                    MoveTest = 64
                    SingleStep
                End If
            Next N
        End If
    End If
    If GameOver = 1 Or Checked > 0 Then Exit Sub
    If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Dolphin" Then
        Pieces(Abs(Squares(InitFile, InitRank))).Moves(7) = 0
        Pieces(Abs(Squares(InitFile, InitRank))).Moves(8) = 0
    End If
    If SpecPower$ = "L" Then SpecialMove
    If Pieces(Abs(Squares(InitFile, InitRank))).Name = "Teaching King" And TeachVer = 2 Then
        If LionPiece = I Then Lion Else TeachingKing
    End If
End If
End Sub

Sub WaDrop()
Response% = MsgBox("Play Game with Drops?", 36, "Wa Shogi")
If Response% = 6 Then
    Drop = 1
    Boardbmp = "Waboard2.bmp"
End If
End Sub

