_TITLE "Barragoon by Robert Witter and Frank Warneke - Programmed by Donald L. Foster Jr. 2017"

_LIMIT 50

SCREEN _NEWIMAGE(1210, 737, 256)

_PALETTECOLOR 2, _RGB32(89, 19, 0) '     Board Seporator
_PALETTECOLOR 3, _RGB32(225, 201, 165) '  Board Light Square
_PALETTECOLOR 4, _RGB32(192, 154, 105) '  Board Dark Square
_PALETTECOLOR 5, _RGB32(100, 100, 100) '  Barragon Top
_PALETTECOLOR 6, _RGB32(135, 111, 75) '     Barragoon Sides
_PALETTECOLOR 7, _RGB32(255, 255, 255) '  White Tile Top
_PALETTECOLOR 8, _RGB32(115, 85, 55) '  White Tile Side
_PALETTECOLOR 9, _RGB32(190, 85, 10) '    Brown Tile Top
_PALETTECOLOR 10, _RGB32(255, 0, 0) '    Brown Tile Side

Player = 1: Opponant = 2

Tiles(1) = 7: Tiles(2) = 7
Barragoon(1, 5) = 1: Barragoon(2, 4) = 1: Barragoon(2, 6) = 1: Barragoon(3, 5) = 1: Barragoon(5, 5) = 1: Barragoon(6, 4) = 1: Barragoon(6, 6) = 1: Barragoon(7, 5) = 1
Rotation(1, 5) = 1: Rotation(2, 4) = 1: Rotation(2, 6) = 1: Rotation(3, 5) = 1: Rotation(5, 5) = 1: Rotation(6, 4) = 1: Rotation(6, 6) = 1: Rotation(7, 5) = 1
Rotate(1) = 1: Rotate(2) = 4: Rotate(3) = 2: Rotate(4) = 4: Rotate(5) = 4: Rotate(6) = 1
TileColor(2, 1) = 1: TileColor(3, 1) = 1: TileColor(3, 2) = 1: TileColor(4, 2) = 1: TileColor(5, 1) = 1: TileColor(5, 2) = 1: TileColor(6, 1) = 1
TileColor(2, 9) = 2: TileColor(3, 8) = 2: TileColor(3, 9) = 2: TileColor(4, 8) = 2: TileColor(5, 9) = 2: TileColor(5, 8) = 2: TileColor(6, 9) = 2
TilePiece(2, 1) = 4: TilePiece(3, 1) = 3: TilePiece(3, 2) = 2: TilePiece(4, 2) = 3: TilePiece(5, 1) = 3: TilePiece(5, 2) = 2: TilePiece(6, 1) = 4
TilePiece(2, 9) = 4: TilePiece(3, 9) = 3: TilePiece(3, 8) = 2: TilePiece(4, 8) = 3: TilePiece(5, 9) = 3: TilePiece(5, 8) = 2: TilePiece(6, 9) = 4

Arrow$ = "BH4BU2BL1C15E1U8R2H4G4R2D7L7U2G4F4U2R8E1BH1P15,15BF7"
Barragoon$(1, 1) = "BL3C15H12E4F11E11F4G11F11G4H11G11H4E11BR5P15,15"
Barragoon$(2, 1) = "BD16C15L3U25L6E9F9L6D25L4BU5P15,15"
Barragoon$(2, 2) = "BL16C15U3R25U6F9G9U6L25U4BR5P15,15"
Barragoon$(2, 3) = "BU16C15R3D25R6G9H9R6U25R4BD5P15,15"
Barragoon$(2, 4) = "BR16C15D3L25D6H9E9D6R25D4BL5P15,15"
Barragoon$(3, 2) = "BL3C15U8L6E9F9L6D16R6G9H9R6U8BR3P15,15"
Barragoon$(3, 1) = "BU3C15R8U6F9G9U6L16D6H9E9D6R8BD3P15,15"
Barragoon$(4, 1) = "BL6BU3C15R12D6E9H9D6L18D24R6U18BU3P15,15"
Barragoon$(4, 2) = "BU6BR3C15D12L6F9E9L6U18L24D6R18BR3P15,15"
Barragoon$(4, 3) = "BR6BD3C15L12U6G9F9U6R18U24L6D18BD3P15,15"
Barragoon$(4, 4) = "BD6BL3C15U12R6H9G9R6D18R24U6L18BL3P15,15"
Barragoon$(5, 1) = "BR6BU3C15L12D6H9E9D6R18D24L6U18BU3P15,15"
Barragoon$(5, 2) = "BU6BL3C15D12R6G9H9R6U18R24D6L18BL3P15,15"
Barragoon$(5, 3) = "BD3BL6C15R12U6F9G9U6L18U24R6D18BD3P15,15"
Barragoon$(5, 4) = "BD6BR3C15U12L6E9F9L6D18L24U6R18BR3P15,15"
Barragoon$(6, 1) = "TA0" + Arrow$ + "TA90" + Arrow$ + "TA180" + Arrow$ + "TA270" + Arrow$
YesNo$(1) = "Yes": YesNo$(2) = " No "

' Setup Background
LINE (0, 0)-(1210, 737), 1, BF
COLOR 15, 1: LOCATE 2, 122: PRINT "B  A  R  R  A  G  O  O  N";

' Setup Instruction Button
LINE (1005, 695)-(1130, 725), 15, BF
COLOR 0, 15: LOCATE 45, 129: PRINT "Game  Rules";

' Draw Board
LINE (11, 11)-(917, 725), 3, BF: LINE (29, 29)-(899, 707), 2, BF
X = 0
FOR Z = 1 TO 7
    V = 0
    FOR Y = 1 TO 9
        IF (Z + Y) / 2 = FIX((Z + Y) / 2) THEN U = 4 ELSE U = 3
        LINE (80 - 46 + V, 80 - 46 + X)-(80 + 46 + V, 80 + 46 + X), U, BF
        IF TilePiece(Z, Y) > 0 THEN X1 = 80 + V: X2 = 80 + X: X3 = TileColor(Z, Y): X4 = TilePiece(Z, Y): X5 = U: GOSUB DrawTile
        IF Barragoon(Z, Y) > 0 THEN X1 = 80 + V: X2 = 80 + X: X3 = Barragoon(Z, Y): X4 = Rotation(Z, Y): GOSUB DrawBarragoon
        BoardX(Z, Y) = 80 + V: BoardY(Z, Y) = 80 + X
        V = V + 96
    NEXT
    X = X + 96
NEXT

' Ask if players want alternative setup for Barragoon pieces.
COLOR 15, 1: LOCATE 13, 125: PRINT "Alternative Setup?";

' Setup Yes and No Buttons.
X = 0: V = 0
FOR Z = 1 TO 2
    LINE (1005, 280 + X)-(1130, 310 + X), 15, BF
    COLOR 0, 15: LOCATE 19 + V, 133: PRINT YesNo$(Z);
    VariationY(Z) = 280 + X
    X = X + 80: V = V + 5
NEXT

' Get Mouse Input for Buttons and Game Rules Button.
AlternativeSetup:
DO WHILE _MOUSEINPUT
    MouseX = _MOUSEX: MouseY = _MOUSEY: MouseLeftButton = _MOUSEBUTTON(1)
    IF (MouseLeftButton = -1) * (MouseX > 1005) * (MouseX < 1130) * (MouseY > 695) * (MouseY < 725) THEN GOSUB ReleaseMouseButton: SHELL "Barragoon Rules.pdf"
    FOR Z = 1 TO 2
        IF (MouseLeftButton = -1) * (MouseX > 1005) * (MouseX < 1130) * (MouseY > VariationY(Z) - 1) * (MouseY < VariationY(Z) + 31) THEN Alternative = Z: GOTO EndChoice1
    NEXT
LOOP
GOTO AlternativeSetup

EndChoice1:
LINE (1005, 280)-(1130, 390), 1, BF

' If Alternative Setup, change Barragoons to All Turn.
IF Alternative = 1 THEN
    FOR Z = 1 TO 7
        FOR Y = 1 TO 9
            IF Barragoon(Z, Y) = 1 THEN Barragoon(Z, Y) = 6: X1 = BoardX(Z, Y): X2 = BoardY(Z, Y): X3 = 6: X4 = 1: GOSUB DrawBarragoon
        NEXT
    NEXT
END IF

StartGame:
' Draw Player Indicator
X1 = 1067: X2 = 100: X3 = Player: X4 = 2: X5 = 1: GOSUB DrawTile
COLOR 15, 1: LOCATE 10, 130: PRINT "Player:"; Player;

' Check for Can't Play
X = 0
FOR Z = 1 TO 7
    FOR Y = 1 TO 9
        IF TileColor(Z, Y) = Player THEN X1 = Z: X2 = Y: Piece = TilePiece(Z, Y): ON Piece GOSUB Piece1, Piece2, Piece3, Piece4
    NEXT
NEXT

' Player Has No Playable Moves, Declare Opponant Winner
IF X = 0 THEN
    COLOR 15, 1: LOCATE 13, 121: PRINT "  You Have No Legal Moves   ";
    COLOR 15, 1: LOCATE 15, 121: PRINT " Press <ENTER> To Continue   ";
    GetENTER: A$ = INKEY$: IF A$ = "" GOTO GetENTER
    IF ASC(A$) <> 13 GOTO GetENTER
    Winner = Opponant: GOTO Winner
END IF

' Set All Playable Locations to 0
FOR Z = 1 TO 7: FOR Y = 1 TO 9: Playable(Z, Y) = 0: NEXT: NEXT

Capture = 0: Barragoon = 0

COLOR 15, 1: LOCATE 13, 121: PRINT "   Choose A Piece To Move   ";

' Get Choose a Piece to Move Mouse Input and Game Rules Button.
ChooseAPieceMouseInput:
DO WHILE _MOUSEINPUT
    MouseX = _MOUSEX: MouseY = _MOUSEY: MouseLeftButton = _MOUSEBUTTON(1)
    IF (MouseLeftButton = -1) * (MouseX > 1005) * (MouseX < 1130) * (MouseY > 695) * (MouseY < 725) THEN GOSUB ReleaseMouseButton: SHELL "Barragoon Rules.pdf"
    FOR Z = 1 TO 7
        FOR Y = 1 TO 9
            IF (MouseLeftButton = -1) * (MouseX > BoardX(Z, Y) - 47) * (MouseX < BoardX(Z, Y) + 47) * (MouseY > BoardY(Z, Y) - 47) * (MouseY < BoardY(Z, Y) + 47) THEN
                IF TileColor(Z, Y) = Player THEN Row1 = Z: Column1 = Y: Piece = TilePiece(Z, Y): GOTO EndChoice2
            END IF
        NEXT
    NEXT
LOOP
GOTO ChooseAPieceMouseInput

EndChoice2:

' Check for Playable Moves
X = 0: X1 = Row1: X2 = Column1: ON Piece GOSUB Piece1, Piece2, Piece3, Piece4

' Is Move Playable?
IF X = 0 GOTO ChooseAPieceMouseInput

' Highlight Selected Square
PAINT (BoardX(Row1, Column1), BoardY(Row1, Column1) + 40), 6, 2

' Highlight Playable Squares
FOR Z = 1 TO 7
    FOR Y = 1 TO 9
        IF Playable(Z, Y) = 1 THEN PAINT (BoardX(Z, Y), BoardY(Z, Y) + 40), 8, 2
    NEXT
NEXT

COLOR 15, 1: LOCATE 13, 121: PRINT "Choose A Location To Move To";

' Get Choose a Piece to Move Mouse Input and Game Rules Button.
ChooseALocationMouseInput:
DO WHILE _MOUSEINPUT
    MouseX = _MOUSEX: MouseY = _MOUSEY: MouseLeftButton = _MOUSEBUTTON(1)
    IF (MouseLeftButton = -1) * (MouseX > 1005) * (MouseX < 1130) * (MouseY > 695) * (MouseY < 725) THEN GOSUB ReleaseMouseButton: SHELL "Barragoon Rules.pdf"
    FOR Z = 1 TO 7
        FOR Y = 1 TO 9
            IF (MouseLeftButton = -1) * (MouseX > BoardX(Z, Y) - 47) * (MouseX < BoardX(Z, Y) + 47) * (MouseY > BoardY(Z, Y) - 47) * (MouseY < BoardY(Z, Y) + 47) THEN
                IF Playable(Z, Y) = 1 THEN Row2 = Z: Column2 = Y: GOTO EndChoice3
            END IF
        NEXT
    NEXT
LOOP
GOTO ChooseALocationMouseInput

EndChoice3:

' Remove Playable Squares
FOR Z = 1 TO 7
    FOR Y = 1 TO 9
        IF (Z + Y) / 2 = FIX((Z + Y) / 2) THEN U = 4 ELSE U = 3
        IF Playable(Z, Y) = 1 THEN Playable(Z, Y) = 0: PAINT (BoardX(Z, Y), BoardY(Z, Y) + 40), U, 2
    NEXT
NEXT

' Remove Selected Piece
IF (Row1 + Column1) / 2 = FIX((Row1 + Column1) / 2) THEN U = 4 ELSE U = 3
LINE (BoardX(Row1, Column1) - 46, BoardY(Row1, Column1) - 46)-(BoardX(Row1, Column1) + 46, BoardY(Row1, Column1) + 46), U, BF

' Check for Capture or Barragoon at New Square
IF TileColor(Row2, Column2) = Opponant THEN Capture = 1: Tiles(Opponant) = Tiles(Opponant) - 1
IF Barragoon(Row2, Column2) > 0 THEN Barragoon = 1

' Move Piece to New Square
TileColor(Row2, Column2) = Player: TilePiece(Row2, Column2) = Piece
Barragoon(Row2, Column2) = 0: Rotation(Row2, Column2) = 0
TileColor(Row1, Column1) = 0: TilePiece(Row1, Column1) = 0

' Draw Player's Tile at New Square
IF (Row2 + Column2) / 2 = FIX((Row2 + Column2) / 2) THEN X5 = 4 ELSE X5 = 3
X1 = BoardX(Row2, Column2): X2 = BoardY(Row2, Column2): X3 = Player: X4 = Piece: GOSUB DrawTile

' Check for Barragoon Placement
BarragoonPlayer = 0
IF Barragoon = 1 THEN BarragoonPlayer = Player
IF Capture = 1 THEN BarragoonPlayer = Opponant

' No Barragoons Needs to be Placed
IF BarragoonPlayer = 0 GOTO CheckWinner

ChooseBarragoonPiece:

' Draw Player Indicator
X1 = 1067: X2 = 100: X3 = BarragoonPlayer: X4 = 2: X5 = 1: GOSUB DrawTile
COLOR 15, 1: LOCATE 10, 130: PRINT "Player:"; BarragoonPlayer;

COLOR 15, 1: LOCATE 13, 121: PRINT "     Choose A Barragoon      ";

' Draw Barragoon List
W = 0
FOR Z = 1 TO 6
    X1 = 1067: X2 = 250 + W: X3 = Z: X4 = 1: X5 = 1: GOSUB DrawBarragoon
    BarragoonY(Z) = 250 + W: W = W + 80
NEXT

' Get Barragoon Piece Input
ChooseBarragoonMouseInput:
DO WHILE _MOUSEINPUT
    MouseX = _MOUSEX: MouseY = _MOUSEY: MouseLeftButton = _MOUSEBUTTON(1)
    IF (MouseLeftButton = -1) * (MouseX > 1005) * (MouseX < 1130) * (MouseY > 695) * (MouseY < 725) THEN GOSUB ReleaseMouseButton: SHELL "Barragoon Rules.pdf"
    FOR Z = 1 TO 6
        IF (MouseX > 1032) * (MouseX < 1102) * (MouseY > BarragoonY(Z) - 35) * (MouseY < BarragoonY(Z) + 35) THEN
            CanSelect = 1: LINE (1032, BarragoonY(Z) - 35)-(1102, BarragoonY(Z) + 35), 15, B
        ELSE
            CanSelect = 0: LINE (1032, BarragoonY(Z) - 35)-(1102, BarragoonY(Z) + 35), 1, B
        END IF
        IF (MouseLeftButton = -1) * (CanSelect = 1) THEN BarragoonPiece = Z: GOSUB ReleaseMouseButton: GOTO EndChoice4
    NEXT
LOOP
GOTO ChooseBarragoonMouseInput

EndChoice4:

' Skip Get Rotation if Barragoon only has 1 Rotation
IF Rotate(BarragoonPiece) = 1 THEN BarragoonRotation = 1: GOTO ChooseLocation

' Remove Barragoon Pieces List
LINE (1032, 215)-(1102, 685), 1, BF

COLOR 15, 1: LOCATE 13, 121: PRINT "     Choose A Rotation      ";

' Draw Barragoon Rotations
W = 0
FOR Z = 1 TO Rotate(BarragoonPiece)
    X1 = 1067: X2 = 250 + W: X3 = BarragoonPiece: X4 = Z: X5 = 1: GOSUB DrawBarragoon
    BarragoonY(Z) = 250 + W: W = W + 80
NEXT

' Get Barragoon Rotation Input
ChooseRotationMouseInput:
DO WHILE _MOUSEINPUT
    MouseX = _MOUSEX: MouseY = _MOUSEY: MouseLeftButton = _MOUSEBUTTON(1)
    IF (MouseLeftButton = -1) * (MouseX > 1005) * (MouseX < 1130) * (MouseY > 695) * (MouseY < 725) THEN GOSUB ReleaseMouseButton: SHELL "Barragoon Rules.pdf"
    FOR Z = 1 TO Rotate(BarragoonPiece)
        IF (MouseX > 1032) * (MouseX < 1102) * (MouseY > BarragoonY(Z) - 35) * (MouseY < BarragoonY(Z) + 35) THEN
            CanSelect = 1: LINE (1032, BarragoonY(Z) - 35)-(1102, BarragoonY(Z) + 35), 15, B
        ELSE
            CanSelect = 0: LINE (1032, BarragoonY(Z) - 35)-(1102, BarragoonY(Z) + 35), 1, B
        END IF
        IF (MouseLeftButton = -1) * (CanSelect = 1) THEN BarragoonRotation = Z: GOSUB ReleaseMouseButton: GOTO EndChoice5
    NEXT
LOOP
GOTO ChooseRotationMouseInput

EndChoice5:

ChooseLocation:
COLOR 15, 1: LOCATE 13, 121: PRINT "     Choose A Location      ";

' Get Choose a Piece to Move Mouse Input and Game Rules Button.
ChooseALocationMouseInput2:
DO WHILE _MOUSEINPUT
    MouseX = _MOUSEX: MouseY = _MOUSEY: MouseLeftButton = _MOUSEBUTTON(1)
    IF (MouseLeftButton = -1) * (MouseX > 1005) * (MouseX < 1130) * (MouseY > 695) * (MouseY < 725) THEN GOSUB ReleaseMouseButton: SHELL "Barragoon Rules.pdf"
    FOR Z = 1 TO 7
        FOR Y = 1 TO 9
            IF (MouseLeftButton = -1) * (MouseX > BoardX(Z, Y) - 47) * (MouseX < BoardX(Z, Y) + 47) * (MouseY > BoardY(Z, Y) - 47) * (MouseY < BoardY(Z, Y) + 47) THEN
                IF (TileColor(Z, Y) = 0) * (Barragoon(Z, Y) = 0) THEN Row2 = Z: Column2 = Y: Selected = 1: GOTO EndChoice6
            END IF
        NEXT
    NEXT
LOOP
GOTO ChooseALocationMouseInput2

EndChoice6:
LINE (1032, 215)-(1102, 685), 1, BF

' Place Barragoon on the Board
Barragoon(Row2, Column2) = BarragoonPiece: Rotation(Row2, Column2) = BarragoonRotation

' Draw Barragoon
X1 = BoardX(Row2, Column2): X2 = BoardY(Row2, Column2): X3 = BarragoonPiece: X4 = BarragoonRotation: GOSUB DrawBarragoon

' If Opponant Placed a Barragoon, Go Back so Player Can Place Barragoon
IF BarragoonPlayer = Opponant THEN BarragoonPlayer = Player: GOTO ChooseBarragoonPiece

CheckWinner:
' Declare Player Winner if Opponant Has No Tiles Left
IF Tiles(Opponant) = 0 THEN Winner = Player: GOTO Winner

SWAP Player, Opponant: GOTO StartGame


ReleaseMouseButton:
DO WHILE _MOUSEINPUT
    IF _MOUSEBUTTON(1) = 0 THEN RETURN
LOOP
GOTO ReleaseMouseButton


DrawTile:
LINE (X1 - 40, X2 - 40)-(X1 + 40, X2 + 40), X5, BF
IF X3 = 1 THEN X5 = 7: X6 = 0 ELSE X5 = 9: X6 = 15
CIRCLE (X1, X2), 35, 2: PAINT (X1, X2), X5, 2
IF (X4 = 2) + (X4 = 4) THEN CIRCLE (X1 - 12, X2 - 12), 6, X6: PAINT (X1 - 12, X2 - 12), X6: CIRCLE (X1 + 12, X2 + 12), 6, X6: PAINT (X1 + 12, X2 + 12), X6
IF (X4 = 4) + ((X4 = 3) * (X3 = 1)) THEN CIRCLE (X1 - 12, X2 - 12), 6, X6: PAINT (X1 - 12, X2 - 12), X6: CIRCLE (X1 - 12, X2 + 12), 6, X6: PAINT (X1 - 12, X2 + 12), X6
IF (X4 = 4) + ((X4 = 3) * (X3 = 2)) THEN CIRCLE (X1 + 12, X2 - 12), 6, X6: PAINT (X1 + 12, X2 - 12), X6: CIRCLE (X1 + 12, X2 + 12), 6, X6: PAINT (X1 + 12, X2 + 10), X6
IF (X4 = 3) * (X3 = 1) THEN CIRCLE (X1 + 12, X2), 6, X6: PAINT (X1 + 12, X2), X6 ELSE IF X4 = 3 THEN CIRCLE (X1 - 12, X2), 6, X6: PAINT (X1 - 12, X2), X6
IF X4 = 2 THEN PSET (X1 - 12, X2 - 12), X6: DRAW "TA0E1F25G3H25E2": PAINT (X1, X2), X6
IF (X4 = 4) + ((X4 = 3) * (X3 = 1)) THEN LINE (X1 - 13, X2 - 12)-(X1 - 10, X2 + 12), X6, BF
IF (X4 = 4) + ((X4 = 3) * (X3 = 2)) THEN LINE (X1 + 13, X2 - 12)-(X1 + 10, X2 + 12), X6, BF
IF (X4 = 3) * (X3 = 1) THEN
    LINE (X1 - 10, X2 - 12)-(X1 + 12, X2 - 2), X6: LINE (X1 - 12, X2 - 10)-(X1 + 12, X2 + 2), X6: PAINT (X1, X2 - 6), X6
    LINE (X1 - 10, X2 + 12)-(X1 + 12, X2 + 2), X6: LINE (X1 - 12, X2 + 10)-(X1 + 12, X2 - 2), X6: PAINT (X1, X2 + 6), X6
END IF
IF (X4 = 3) * (X3 = 2) THEN
    LINE (X1 + 10, X2 - 12)-(X1 - 12, X2 - 2), X6: LINE (X1 + 12, X2 - 10)-(X1 - 12, X2 + 2), X6: PAINT (X1, X2 - 6), X6
    LINE (X1 + 10, X2 + 12)-(X1 - 12, X2 + 2), X6: LINE (X1 + 12, X2 + 10)-(X1 - 12, X2 - 2), X6: PAINT (X1, X2 + 6), X6
END IF
IF X4 = 4 THEN LINE (X1 - 12, X2 - 13)-(X1 + 12, X2 - 10), X6, BF: LINE (X1 - 12, X2 + 13)-(X1 + 12, X2 + 10), X6, BF
RETURN


DrawBarragoon:
LINE (X1 - 25, X2 - 25)-(X1 + 25, X2 + 25), 2, B: PAINT (X1, X2), 0, 2: PSET (X1, X2), 0: DRAW Barragoon$(X3, X4): RETURN


Piece1: RETURN

Piece2: GOSUB Start1Space: RETURN

Piece3: GOSUB Start1Space: GOSUB Start2Spaces: RETURN

Piece4: GOSUB Start1Space: GOSUB Start2Spaces: GOSUB Start3Spaces: RETURN


Start1Space:
' 1 Start Up Direction
IF X1 - 1 >= 1 THEN
    IF (TileColor(X1 - 1, X2) = 0) * ((Barragoon(X1 - 1, X2) = 0) + ((Barragoon(X1 - 1, X2) = 5) * (Rotation(X1 - 1, X2) = 1)) + (Barragoon(X1 - 1, X2) = 6)) THEN Y1 = X1 - 1: Y2 = X2: Moves = 1: V = 0: GOSUB CheckLeft
    IF (TileColor(X1 - 1, X2) = 0) * ((Barragoon(X1 - 1, X2) = 0) + ((Barragoon(X1 - 1, X2) = 2) * (Rotation(X1 - 1, X2) = 1)) + ((Barragoon(X1 - 1, X2) = 3) * (Rotation(X1 - 1, X2) = 2))) THEN Y1 = X1 - 1: Y2 = X2: Moves = 1: V = 0: GOSUB CheckUp
    IF (TileColor(X1 - 1, X2) = 0) * ((Barragoon(X1 - 1, X2) = 0) + ((Barragoon(X1 - 1, X2) = 4) * (Rotation(X1 - 1, X2) = 1)) + (Barragoon(X1 - 1, X2) = 6)) THEN Y1 = X1 - 1: Y2 = X2: Moves = 1: V = 0: GOSUB CheckRight
END IF

' 1 Start Right Direction
IF X2 + 1 <= 9 THEN
    IF (TileColor(X1, X2 + 1) = 0) * ((Barragoon(X1, X2 + 1) = 0) + ((Barragoon(X1, X2 + 1) = 4) * (Rotation(X1, X2 + 1) = 2)) + (Barragoon(X1, X2 + 1) = 6)) THEN Y1 = X1: Y2 = X2 + 1: Moves = 1: V = 0: GOSUB CheckDown
    IF (TileColor(X1, X2 + 1) = 0) * ((Barragoon(X1, X2 + 1) = 0) + ((Barragoon(X1, X2 + 1) = 5) * (Rotation(X1, X2 + 1) = 2)) + (Barragoon(X1, X2 + 1) = 6)) THEN Y1 = X1: Y2 = X2 + 1: Moves = 1: V = 0: GOSUB CheckUp
    IF (TileColor(X1, X2 + 1) = 0) * ((Barragoon(X1, X2 + 1) = 0) + ((Barragoon(X1, X2 + 1) = 2) * (Rotation(X1, X2 + 1) = 2)) + ((Barragoon(X1, X2 + 1) = 3) * (Rotation(X1, X2 + 1) = 1))) THEN Y1 = X1: Y2 = X2 + 1: Moves = 1: V = 0: GOSUB CheckRight
END IF

' 1 Start Down Direction
IF X1 + 1 <= 7 THEN
    IF (TileColor(X1 + 1, X2) = 0) * ((Barragoon(X1 + 1, X2) = 0) + ((Barragoon(X1 + 1, X2) = 4) * (Rotation(X1 + 1, X2) = 3)) + (Barragoon(X1 + 1, X2) = 6)) THEN Y1 = X1 + 1: Y2 = X2: Moves = 1: V = 0: GOSUB CheckLeft
    IF (TileColor(X1 + 1, X2) = 0) * ((Barragoon(X1 + 1, X2) = 0) + ((Barragoon(X1 + 1, X2) = 2) * (Rotation(X1 + 1, X2) = 3)) + ((Barragoon(X1 + 1, X2) = 3) * (Rotation(X1 + 1, X2) = 2))) THEN Y1 = X1 + 1: Y2 = X2: Moves = 1: V = 0: GOSUB CheckDown
    IF (TileColor(X1 + 1, X2) = 0) * ((Barragoon(X1 + 1, X2) = 0) + ((Barragoon(X1 + 1, X2) = 5) * (Rotation(X1 + 1, X2) = 3)) + (Barragoon(X1 + 1, X2) = 6)) THEN Y1 = X1 + 1: Y2 = X2: Moves = 1: V = 0: GOSUB CheckRight
END IF

' 1 Start Left Direction
IF X2 - 1 >= 1 THEN
    IF (TileColor(X1, X2 - 1) = 0) * ((Barragoon(X1, X2 - 1) = 0) + ((Barragoon(X1, X2 - 1) = 2) * (Rotation(X1, X2 - 1) = 4)) + ((Barragoon(X1, X2 - 1) = 3) * (Rotation(X1, X2 - 1) = 1))) THEN Y1 = X1: Y2 = X2 - 1: Moves = 1: V = 0: GOSUB CheckLeft
    IF (TileColor(X1, X2 - 1) = 0) * ((Barragoon(X1, X2 - 1) = 0) + ((Barragoon(X1, X2 - 1) = 4) * (Rotation(X1, X2 - 1) = 4)) + (Barragoon(X1, X2 - 1) = 6)) THEN Y1 = X1: Y2 = X2 - 1: Moves = 1: V = 0: GOSUB CheckUp
    IF (TileColor(X1, X2 - 1) = 0) * ((Barragoon(X1, X2 - 1) = 0) + ((Barragoon(X1, X2 - 1) = 5) * (Rotation(X1, X2 - 1) = 4)) + (Barragoon(X1, X2 - 1) = 6)) THEN Y1 = X1: Y2 = X2 - 1: Moves = 1: V = 0: GOSUB CheckDown
END IF
RETURN


Start2Spaces:
' 2 Start Up Then Turn
IF X1 - 2 >= 1 THEN
    IF (TileColor(X1 - 1, X2) = 0) * (TileColor(X1 - 2, X2) = 0) * ((Barragoon(X1 - 1, X2) = 0) + ((Barragoon(X1 - 1, X2) = 2) * (Rotation(X1 - 1, X2) = 1)) + ((Barragoon(X1 - 1, X2) = 3) * (Rotation(X1 - 1, X2) = 2))) * ((Barragoon(X1 - 2, X2) = 0) + ((Barragoon(X1 - 2, X2) = 5) * (Rotation(X1 - 2, X2) = 1)) + (Barragoon(X1 - 2, X2) = 6)) THEN Y1 = X1 - 2: Y2 = X2: Moves = 2: V = 0: GOSUB CheckLeft
    IF (TileColor(X1 - 1, X2) = 0) * (TileColor(X1 - 2, X2) = 0) * ((Barragoon(X1 - 1, X2) = 0) + ((Barragoon(X1 - 1, X2) = 2) * (Rotation(X1 - 1, X2) = 1)) + ((Barragoon(X1 - 1, X2) = 3) * (Rotation(X1 - 1, X2) = 2))) * ((Barragoon(X1 - 2, X2) = 0) + ((Barragoon(X1 - 2, X2) = 2) * (Rotation(X1 - 2, X2) = 1)) + ((Barragoon(X1 - 2, X2) = 3) * (Rotation(X1 - 1, X2) = 2))) THEN Y1 = X1 - 2: Y2 = X2: Moves = 2: V = 0: GOSUB CheckUp
    IF (TileColor(X1 - 1, X2) = 0) * (TileColor(X1 - 2, X2) = 0) * ((Barragoon(X1 - 1, X2) = 0) + ((Barragoon(X1 - 1, X2) = 2) * (Rotation(X1 - 1, X2) = 1)) + ((Barragoon(X1 - 1, X2) = 3) * (Rotation(X1 - 1, X2) = 2))) * ((Barragoon(X1 - 2, X2) = 0) + ((Barragoon(X1 - 2, X2) = 4) * (Rotation(X1 - 2, X2) = 1)) + (Barragoon(X1 - 2, X2) = 6)) THEN Y1 = X1 - 2: Y2 = X2: Moves = 2: V = 0: GOSUB CheckRight
END IF

' 2 Start Right Then Turn
IF X2 + 2 <= 9 THEN
    IF (TileColor(X1, X2 + 1) = 0) * (TileColor(X1, X2 + 2) = 0) * ((Barragoon(X1, X2 + 1) = 0) + ((Barragoon(X1, X2 + 1) = 2) * (Rotation(X1, X2 + 1) = 2)) + ((Barragoon(X1, X2 + 1) = 3) * (Rotation(X1, X2 + 1) = 1))) * ((Barragoon(X1, X2 + 2) = 0) + ((Barragoon(X1, X2 + 2) = 4) * (Rotatiom(X1, X2 + 2) = 2)) + (Barragoon(X1, X2 + 2) = 6)) THEN Y1 = X1: Y2 = X2 + 2: Moves = 2: V = 0: GOSUB CheckDown
    IF (TileColor(X1, X2 + 1) = 0) * (TileColor(X1, X2 + 2) = 0) * ((Barragoon(X1, X2 + 1) = 0) + ((Barragoon(X1, X2 + 1) = 2) * (Rotation(X1, X2 + 1) = 2)) + ((Barragoon(X1, X2 + 1) = 3) * (Rotation(X1, X2 + 1) = 1))) * ((Barragoon(X1, X2 + 2) = 0) + ((Barragoon(X1, X2 + 2) = 5) * (Rotatiom(X1, X2 + 2) = 2)) + (Barragoon(X1, X2 + 2) = 6)) THEN Y1 = X1: Y2 = X2 + 2: Moves = 2: V = 0: GOSUB CheckUp
    IF (TileColor(X1, X2 + 1) = 0) * (TileColor(X1, X2 + 2) = 0) * ((Barragoon(X1, X2 + 1) = 0) + ((Barragoon(X1, X2 + 1) = 2) * (Rotation(X1, X2 + 1) = 2)) + ((Barragoon(X1, X2 + 1) = 3) * (Rotation(X1, X2 + 1) = 1))) * ((Barragoon(X1, X2 + 2) = 0) + ((Barragoon(X1, X2 + 2) = 2) * (Rotatiom(X1, X2 + 2) = 2)) + ((Barragoon(X1, X2 + 2) = 3) * (Rotation(X1, X2 + 2) = 1))) THEN Y1 = X1: Y2 = X2 + 2: Moves = 2: V = 0: GOSUB CheckRight
END IF

' 2 Start Down Then Turn
IF X1 + 2 <= 7 THEN
    IF (TileColor(X1 + 1, X2) = 0) * (TileColor(X1 + 2, X2) = 0) * ((Barragoon(X1 + 1, X2) = 0) + ((Barragoon(X1 + 1, X2) = 2) * (Rotation(X1 + 1, X2) = 3)) + ((Barragoon(X1 + 1, X2) = 3) * (Rotation(X1 + 1, X2) = 2))) * ((Barragoon(X1 + 2, X2) = 0) + ((Barragoon(X1 + 2, X2) = 4) * (Rotation(X1 + 2, X2) = 3)) + (Barragoon(X1 + 2, X2) = 6)) THEN Y1 = X1 + 2: Y2 = X2: Moves = 2: V = 0: GOSUB CheckLeft
    IF (TileColor(X1 + 1, X2) = 0) * (TileColor(X1 + 2, X2) = 0) * ((Barragoon(X1 + 1, X2) = 0) + ((Barragoon(X1 + 1, X2) = 2) * (Rotation(X1 + 1, X2) = 3)) + ((Barragoon(X1 + 1, X2) = 3) * (Rotation(X1 + 1, X2) = 2))) * ((Barragoon(X1 + 2, X2) = 0) + ((Barragoon(X1 + 2, X2) = 2) * (Rotation(X1 + 2, X2) = 3)) + ((Barragoon(X1 + 2, X2) = 3) * (Rotation(X1 + 2, X2) = 2))) THEN Y1 = X1 + 2: Y2 = X2: Moves = 2: V = 0: GOSUB CheckDown
    IF (TileColor(X1 + 1, X2) = 0) * (TileColor(X1 + 2, X2) = 0) * ((Barragoon(X1 + 1, X2) = 0) + ((Barragoon(X1 + 1, X2) = 2) * (Rotation(X1 + 1, X2) = 3)) + ((Barragoon(X1 + 1, X2) = 3) * (Rotation(X1 + 1, X2) = 2))) * ((Barragoon(X1 + 2, X2) = 0) + ((Barragoon(X1 + 2, X2) = 5) * (Rotation(X1 + 2, X2) = 3)) + (Barragoon(X1 + 2, X2) = 6)) THEN Y1 = X1 + 2: Y2 = X2: Moves = 2: V = 0: GOSUB CheckRight
END IF

' 2 Start Left Then Turn
IF X2 - 2 >= 1 THEN
    IF (TileColor(X1, X2 - 1) = 0) * (TileColor(X1, X2 - 2) = 0) * ((Barragoon(X1, X2 - 1) = 0) + ((Barragoon(X1, X2 - 1) = 2) * (Roatation(X1, X2 - 1) = 4)) + ((Barragoon(X1, X2 - 1) = 3) * (Rotation(X1, X2 - 1) = 1))) * ((Barragoon(X1, X2 - 2) = 0) + ((Barragoon(X1, X2 - 2) = 2) * (Rotation(X1, X2 - 2) = 2)) + ((Barragoon(X1, X2 - 2) = 3) * (Rotation(X1, X2 - 2) = 1))) THEN Y1 = X1: Y2 = X2 - 2: Moves = 2: V = 0: GOSUB CheckLeft
    IF (TileColor(X1, X2 - 1) = 0) * (TileColor(X1, X2 - 2) = 0) * ((Barragoon(X1, X2 - 1) = 0) + ((Barragoon(X1, X2 - 1) = 2) * (Roatation(X1, X2 - 1) = 4)) + ((Barragoon(X1, X2 - 1) = 3) * (Rotation(X1, X2 - 1) = 1))) * ((Barragoon(X1, X2 - 2) = 0) + ((Barragoon(X1, X2 - 2) = 4) * (Rotation(X1, X2 - 2) = 4)) + (Barragoon(X1, X2 - 2) = 6)) THEN Y1 = X1: Y2 = X2 - 2: Moves = 2: V = 0: GOSUB CheckUp
    IF (TileColor(X1, X2 - 1) = 0) * (TileColor(X1, X2 - 2) = 0) * ((Barragoon(X1, X2 - 1) = 0) + ((Barragoon(X1, X2 - 1) = 2) * (Roatation(X1, X2 - 1) = 4)) + ((Barragoon(X1, X2 - 1) = 3) * (Rotation(X1, X2 - 1) = 1))) * ((Barragoon(X1, X2 - 2) = 0) + ((Barragoon(X1, X2 - 2) = 5) * (Rotation(X1, X2 - 2) = 4)) + (Barragoon(X1, X2 - 2) = 6)) THEN Y1 = X1: Y2 = X2 - 2: Moves = 2: V = 0: GOSUB CheckDown
END IF
RETURN


Start3Spaces:
' 3 Start Up Then Turn
IF X1 - 3 >= 1 THEN
    IF (TileColor(X1 - 1, X2) = 0) * (TileColor(X1 - 2, X2) = 0) * (TileColor(X1 - 3, X2) = 0) * ((Barragoon(X1 - 1, X2) = 0) + ((Barragoon(X1 - 1, X2) = 2) * (Rotation(X1 - 1, X2) = 1)) + ((Barragoon(X1 - 1, X2) = 3) * (Rotation(X1 - 1, X2) = 2))) * ((Barragoon(X1 - 2, X2) = 0) + ((Barragoon(X1 - 2, X2) = 2) * (Rotation(X1 - 2, X2) = 1)) + ((Barragoon(X1 - 2, X2) = 3) * (Rotation(X1 - 2, X2) = 2))) * ((Barragoon(X1 - 3, X2) = 0) + ((Barragoon(X1 - 3, X2) = 5) * (Rotation(X1 - 3, X2) = 1)) + (Barragoon(X1 - 3, X2) = 6)) THEN Y1 = X1 - 3: Y2 = X2: Moves = 3: V = 0: GOSUB CheckLeft
    IF (TileColor(X1 - 1, X2) = 0) * (TileColor(X1 - 2, X2) = 0) * (TileColor(X1 - 3, X2) = 0) * ((Barragoon(X1 - 1, X2) = 0) + ((Barragoon(X1 - 1, X2) = 2) * (Rotation(X1 - 1, X2) = 1)) + ((Barragoon(X1 - 1, X2) = 3) * (Rotation(X1 - 1, X2) = 2))) * ((Barragoon(X1 - 2, X2) = 0) + ((Barragoon(X1 - 2, X2) = 2) * (Rotation(X1 - 2, X2) = 1)) + ((Barragoon(X1 - 2, X2) = 3) * (Rotation(X1 - 1, X2) = 2))) * ((Barragoon(X1 - 3, X2) = 0) + ((Barragoon(X1 - 3, X2) = 2) * (Rotation(X1 - 3, X2) = 1)) + ((Barragoon(X1 - 3, X2) = 2) * (Rotation(X1 - 3, X2) = 2))) THEN Y1 = X1 - 3: Y2 = X2: Moves = 3: V = 0: GOSUB CheckUp
    IF (TileColor(X1 - 1, X2) = 0) * (TileColor(X1 - 2, X2) = 0) * (TileColor(X1 - 3, X2) = 0) * ((Barragoon(X1 - 1, X2) = 0) + ((Barragoon(X1 - 1, X2) = 2) * (Rotation(X1 - 1, X2) = 1)) + ((Barragoon(X1 - 1, X2) = 3) * (Rotation(X1 - 1, X2) = 2))) * ((Barragoon(X1 - 2, X2) = 0) + ((Barragoon(X1 - 2, X2) = 2) * (Rotation(X1 - 2, X2) = 1)) + ((Barragoon(X1 - 2, X2) = 3) * (Rotation(X1 - 2, X2) = 2))) * ((Barragoon(X1 - 3, X2) = 0) + ((Barragoon(X1 - 3, X2) = 4) * (Rotation(X1 - 3, X2) = 1)) + (Barragoon(X1 - 3, X2) = 6)) THEN Y1 = X1 - 3: Y2 = X2: Moves = 3: V = 0: GOSUB CheckRight
END IF

' 3 Start Right Then Turn
IF X2 + 3 <= 9 THEN
    IF (TileColor(X1, X2 + 1) = 0) * (TileColor(X1, X2 + 2) = 0) * (TileColor(X1, X2 + 3) = 0) * ((Barragoon(X1, X2 + 1) = 0) + ((Barragoon(X1, X2 + 1) = 2) * (Rotation(X1, X2 + 1) = 2)) + ((Barragoon(X1, X2 + 1) = 3) * (Rotation(X1, X2 + 1) = 1))) * ((Barragoon(X1, X2 + 2) = 0) + ((Barragoon(X1, X2 + 2) = 2) * (Rotatiom(X1, X2 + 2) = 2)) + ((Barragoon(X1, X2 + 2) = 3) * (Rotation(X1, X2 + 2) = 1))) * ((Barragoon(X1, X2 + 3) = 0) + ((Barragoon(X1, X2 + 3) = 4) * (Rotation(X1, X2 + 3) = 2)) + (Barragoon(X1, X2 + 3) = 6)) THEN Y1 = X1: Y2 = X2 + 3: Moves = 3: V = 0: GOSUB CheckDown
    IF (TileColor(X1, X2 + 1) = 0) * (TileColor(X1, X2 + 2) = 0) * (TileColor(X1, X2 + 3) = 0) * ((Barragoon(X1, X2 + 1) = 0) + ((Barragoon(X1, X2 + 1) = 2) * (Rotation(X1, X2 + 1) = 2)) + ((Barragoon(X1, X2 + 1) = 3) * (Rotation(X1, X2 + 1) = 1))) * ((Barragoon(X1, X2 + 2) = 0) + ((Barragoon(X1, X2 + 2) = 2) * (Rotatiom(X1, X2 + 2) = 2)) + ((Barragoon(X1, X2 + 2) = 6) * (Rotation(X1, X2 + 2) = 1))) * ((Barragoon(X1, X2 + 3) = 0) + ((Barragoon(X1, X2 + 3) = 5) * (Rotation(X1, X2 + 3) = 2)) + (Barragoon(X1, X2 + 3) = 6)) THEN Y1 = X1: Y2 = X2 + 3: Moves = 3: V = 0: GOSUB CheckUp
    IF (TileColor(X1, X2 + 1) = 0) * (TileColor(X1, X2 + 2) = 0) * (TileColor(X1, X2 + 3) = 0) * ((Barragoon(X1, X2 + 1) = 0) + ((Barragoon(X1, X2 + 1) = 2) * (Rotation(X1, X2 + 1) = 2)) + ((Barragoon(X1, X2 + 1) = 3) * (Rotation(X1, X2 + 1) = 1))) * ((Barragoon(X1, X2 + 2) = 0) + ((Barragoon(X1, X2 + 2) = 2) * (Rotatiom(X1, X2 + 2) = 2)) + ((Barragoon(X1, X2 + 2) = 3) * (Rotation(X1, X2 + 2) = 1))) * ((Barragoon(X1, X2 + 3) = 0) + ((Barragoon(X1, X2 + 3) = 2) * (Rotation(X1, X2 + 3) = 2)) + ((Barragoon(X1, X2 + 3) = 3) * (Rotation(X1, X2 + 3) = 1))) THEN Y1 = X1: Y2 = X2 + 3: Moves = 3: V = 0: GOSUB CheckRight
END IF

' 3 Start Down Then Turn
IF X1 + 3 <= 7 THEN
    IF (TileColor(X1 + 1, X2) = 0) * (TileColor(X1 + 2, X2) = 0) * (TileColor(X1 + 3, X2) = 0) * ((Barragoon(X1 + 1, X2) = 0) + ((Barragoon(X1 + 1, X2) = 2) * (Rotation(X1 + 1, X2) = 3)) + ((Barragoon(X1 + 1, X2) = 3) * (Rotation(X1 + 1, X2) = 2))) * ((Barragoon(X1 + 2, X2) = 0) + ((Barragoon(X1 + 2, X2) = 2) * (Rotation(X1 + 2, X2) = 3)) + ((Barragoon(X1 + 2, X2) = 3) * (Rotation(X1 + 2, X2) = 2))) * ((Barragoon(X1 + 3, X2) = 0) + ((Barragoon(X1 + 3, X2) = 4) * (Rotation(X1 + 3, X2) = 3)) + (Barragoon(X1 + 3, X2) = 6)) THEN Y1 = X1 + 3: Y2 = X2: Moves = 3: V = 0: GOSUB CheckLeft
    IF (TileColor(X1 + 1, X2) = 0) * (TileColor(X1 + 2, X2) = 0) * (TileColor(X1 + 3, X2) = 0) * ((Barragoon(X1 + 1, X2) = 0) + ((Barragoon(X1 + 1, X2) = 2) * (Rotation(X1 + 1, X2) = 3)) + ((Barragoon(X1 + 1, X2) = 3) * (Rotation(X1 + 1, X2) = 2))) * ((Barragoon(X1 + 2, X2) = 0) + ((Barragoon(X1 + 2, X2) = 2) * (Rotation(X1 + 2, X2) = 3)) + ((Barragoon(X1 + 2, X2) = 3) * (Rotation(X1 + 2, X2) = 2))) * ((Barragoon(X1 + 3, X2) = 0) + ((Barragoon(X1 + 3, X2) = 2) * (Rotation(X1 + 3, X2) = 3)) + ((Barragoon(X1 + 3, X2) = 3) * (Rotation(X1 + 3, X2) = 1))) THEN Y1 = X1 + 3: Y2 = X2: Moves = 3: V = 0: GOSUB CheckDown
    IF (TileColor(X1 + 1, X2) = 0) * (TileColor(X1 + 2, X2) = 0) * (TileColor(X1 + 3, X2) = 0) * ((Barragoon(X1 + 1, X2) = 0) + ((Barragoon(X1 + 1, X2) = 2) * (Rotation(X1 + 1, X2) = 3)) + ((Barragoon(X1 + 1, X2) = 3) * (Rotation(X1 + 1, X2) = 2))) * ((Barragoon(X1 + 2, X2) = 0) + ((Barragoon(X1 + 2, X2) = 2) * (Rotation(X1 + 2, X2) = 3)) + ((Barragoon(X1 + 2, X2) = 3) * (Rotation(X1 + 2, X2) = 2))) * ((Barragoon(X1 + 3, X2) = 0) + ((Barragoon(X1 + 3, X2) = 5) * (Rotation(X1 + 3, X2) = 3)) + (Barragoon(X1 + 3, X2) = 6)) THEN Y1 = X1 + 3: Y2 = X2: Moves = 3: V = 0: GOSUB CheckRight
END IF

' 3 Start Left Then Turn
IF X2 - 3 >= 1 THEN
    IF (TileColor(X1, X2 - 1) = 0) * (TileColor(X1, X2 - 2) = 0) * (TileColor(X1, X2 - 3) = 0) * ((Barragoon(X1, X2 - 1) = 0) + ((Barragoon(X1, X2 - 1) = 2) * (Rotation(X1, X2 - 1) = 4)) + ((Barragoon(X1, X2 - 1) = 3) * (Rotation(X1, X2 - 1) = 1))) * ((Barragoon(X1, X2 - 2) = 0) + ((Barragoon(X1, X2 - 2) = 2) * (Rotation(X1, X2 - 2) = 4)) + ((Barragoon(X1, X2 - 2) = 3) * (Rotation(X1, X2 - 2) = 1))) * ((Barragoon(X1, X2 - 3) = 0) + ((Barragoon(X1, X2 - 3) = 2) * (Rotation(X1, X2 - 3) = 4)) + ((Barragoon(X1, X2 - 3) = 3) * (Rotation(X1, X2 - 3) = 1))) THEN Y1 = X1: Y2 = X2 - 3: Moves = 3: V = 0: GOSUB CheckLeft
    IF (TileColor(X1, X2 - 1) = 0) * (TileColor(X1, X2 - 2) = 0) * (TileColor(X1, X2 - 3) = 0) * ((Barragoon(X1, X2 - 1) = 0) + ((Barragoon(X1, X2 - 1) = 2) * (Rotation(X1, X2 - 1) = 4)) + ((Barragoon(X1, X2 - 1) = 3) * (Rotation(X1, X2 - 1) = 1))) * ((Barragoon(X1, X2 - 2) = 0) + ((Barragoon(X1, X2 - 2) = 2) * (Rotation(X1, X2 - 2) = 4)) + ((Barragoon(X1, X2 - 2) = 3) * (Rotation(X1, X2 - 2) = 1))) * ((Barragoon(X1, X2 - 3) = 0) + ((Barragoon(X1, X2 - 3) = 4) * (Rotation(X1, X2 - 3) = 4)) + (Barragoon(X1, X2 - 3) = 6)) THEN Y1 = X1: Y2 = X2 - 3: Moves = 3: V = 0: GOSUB CheckUp
    IF (TileColor(X1, X2 - 1) = 0) * (TileColor(X1, X2 - 2) = 0) * (TileColor(X1, X2 - 3) = 0) * ((Barragoon(X1, X2 - 1) = 0) + ((Barragoon(X1, X2 - 1) = 2) * (Rotation(X1, X2 - 1) = 4)) + ((Barragoon(X1, X2 - 1) = 3) * (Rotation(X1, X2 - 1) = 1))) * ((Barragoon(X1, X2 - 2) = 0) + ((Barragoon(X1, X2 - 2) = 2) * (Rotation(X1, X2 - 2) = 4)) + ((Barragoon(X1, X2 - 2) = 3) * (Rotation(X1, X2 - 2) = 1))) * ((Barragoon(X1, X2 - 3) = 0) + ((Barragoon(X1, X2 - 3) = 5) * (Rotation(X1, X2 - 3) = 4)) + (Barragoon(X1, X2 - 3) = 6)) THEN Y1 = X1: Y2 = X2 - 3: Moves = 3: V = 0: GOSUB CheckDown
END IF
RETURN


CheckUp:
IF Moves + V = Piece - 1 THEN IF TileColor(Y1 - V, Y2) + Barragoon(Y1 - V, Y2) = 0 THEN X = 1: Playable(Y1 - V, Y2) = 1: ' Short Move Up
IF Y1 - V - 1 >= 1 THEN
    V = V + 1
    IF Moves + V = Piece THEN
        IF TileColor(Y1 - V, Y2) = Player THEN RETURN
        IF (Piece = 2) * (Barragoon(Y1 - V, Y2) = 6) THEN RETURN
        Playable(Y1 - V, Y2) = 1: X = 1: RETURN
    ELSE
        IF (TileColor(Y1 - V, Y2) = 0) * ((Barragoon(Y1 - V, Y2) = 0) + ((Barragoon(Y1 - V, Y2) = 2) * (Rotation(Y1 - V, Y2) = 1)) + ((Barragoon(Y1 - V, Y2) = 3) * (Rotation(Y1 - V, Y2) = 2))) GOTO CheckUp
        RETURN
    END IF
END IF
RETURN

CheckRight:
IF Moves + V = Piece - 1 THEN IF TileColor(Y1, Y2 + V) + Barragoon(Y1, Y2 + V) = 0 THEN X = 1: Playable(Y1, Y2 + V) = 1: ' Short Move Right
IF Y2 + V + 1 <= 9 THEN
    V = V + 1
    IF Moves + V = Piece THEN
        IF TileColor(Y1, Y2 + V) = Player THEN RETURN
        IF (Piece = 2) * (Barragoon(Y1, Y2 + V) = 6) THEN RETURN
        Playable(Y1, Y2 + V) = 1: X = 1: RETURN
    ELSE
        IF (TileColor(Y1, Y2 + V) = 0) * ((Barragoon(Y1, Y2 + V) = 0) + ((Barragoon(Y1, Y2 + V) = 2) * (Rotation(Y1, Y2 + V) = 2)) + ((Barragoon(Y1, Y2 + V) = 3) * (Rotation(Y1, Y2 + V) = 1))) GOTO CheckRight
        RETURN
    END IF
END IF
RETURN

CheckDown:
IF Moves + V = Piece - 1 THEN IF TileColor(Y1 + V, Y2) + Barragoon(Y1 + V, Y2) = 0 THEN X = 1: Playable(Y1 + V, Y2) = 1: ' Short Move Right
IF Y1 + V + 1 <= 7 THEN
    V = V + 1
    IF Moves + V = Piece THEN
        IF TileColor(Y1 + V, Y2) = Player THEN RETURN
        IF (Piece = 2) * (Barragoon(Y1 + V, Y2) = 6) THEN RETURN
        Playable(Y1 + V, Y2) = 1: X = 1: RETURN
    ELSE
        IF (TileColor(Y1 + V, Y2) = 0) * ((Barragoon(Y1 + V, Y2) = 0) + ((Barragoon(Y1 + V, Y2) = 2) * (Rotation(Y1 + V, Y2) = 3)) + ((Barragoon(Y1 + V, Y2) = 3) * (Rotation(Y1 + V, Y2) = 2))) GOTO CheckDown
        RETURN
    END IF
END IF
RETURN

CheckLeft:
IF Moves + V = Piece - 1 THEN IF TileColor(Y1, Y2 - V) + Barragoon(Y1, Y2 - V) = 0 THEN X = 1: Playable(Y1, Y2 - V) = 1: ' Short Move Left
IF Y2 - V - 1 >= 1 THEN
    V = V + 1
    IF Moves + V = Piece THEN
        IF TileColor(Y1, Y2 - V) = Player THEN RETURN
        IF (Piece = 2) * (Barragoon(Y1, Y2 - V) = 6) THEN RETURN
        Playable(Y1, Y2 - V) = 1: X = 1: RETURN
    ELSE
        IF (TileColor(Y1, Y2 - V) = 0) * ((Barragoon(Y1, Y2 - V) = 0) + ((Barragoon(Y1, Y2 - V) = 2) * (Rotation(Y1, Y2 - V) = 4)) + ((Barragoon(Y1, Y2 - V) = 3) * (Rotation(V1, Y2 - V) = 1))) GOTO CheckLeft
        RETURN
    END IF
END IF
RETURN


Winner:
X1 = 1067: X2 = 100: X3 = Winner: X4 = 2: X5 = 1: GOSUB DrawTile
COLOR 15, 1: LOCATE 10, 130: PRINT "Player:"; Winner;
COLOR 15, 1: LOCATE 13, 121: PRINT "  Player"; Winner; "is the Winner!   ";
COLOR 15, 1: LOCATE 15, 121: PRINT " Play Another Game? Y or N   ";
GetYesNo: A$ = UCASE$(INKEY$): IF A$ = "" GOTO GetYesNo
IF A$ = "Y" THEN RUN
IF A$ = "N" THEN SYSTEM
GOTO GetYesNo














