DECLARE SUB capturegreen (game!(), greeni%, greenj%, gx%, gy%, redi%, redj%, rx%, ry%, redy%)
DECLARE SUB ending (greencount%, redcount%, greenwin%, redwin%, continue$)
DECLARE SUB scoreboard (game(), greencount%, redcount%, redwin%, greenwin%)
DECLARE SUB movered (game!(), redi%, redj%, rx%, ry%, redy%)
DECLARE SUB intro ()
DECLARE SUB gameboard (i%, j%, x%, y%, game!())
DECLARE SUB capturered (game!(), greeni%, greenj%, gx%, gy%)
DECLARE SUB movegreen (game!(), greeni%, greenj%, gx%, gy%, key$)
DECLARE SUB startspots (game!(), rx%, ry%, redj%, redy%, gx%, gy%, greenj%, greeni%)
DECLARE SUB pauser ()
DECLARE SUB circler (rx%, ry%)
DECLARE SUB circleg (gx%, gy%)

CALL intro
CLS
SCREEN 12

DIM game(10, 10)

FOR i% = 1 TO 1000
RANDOMIZE TIMER
greencount% = 0
redcount% = 0
continue$ = "a"
CLS

CALL gameboard(i%, j%, x%, y%, game())
CALL scoreboard(game(), greencount%, redcount%, redwin%, greenwin%)
CALL startspots(game(), rx%, ry%, redj%, redy%, gx%, gy%, greenj%, greeni%)

DO
   DO
      CALL scoreboard(game(), greencount%, redcount%, redwin%, greenwin%)
      LOCATE 28, 2
      PRINT "Press 'q' to Quit. "
      key$ = INKEY$
      IF key$ = "q" THEN
      END
      END IF

      REM -----Move Green Phage-----
      CALL movegreen(game(), greeni%, greenj%, gx%, gy%, key$)
     
    
   LOOP UNTIL key$ <> ""
      CALL capturered(game(), greeni%, greenj%, gx%, gy%)
      CALL scoreboard(game(), greencount%, redcount%, redwin%, greenwin%)
      CALL ending(greencount%, redcount%, greenwin%, redwin%, continue$)
   
    IF continue$ = "a" THEN
      REM -----Move Red Phage-----
      CALL movered(game(), redi%, redj%, rx%, ry%, redy%)
      CALL capturegreen(game(), greeni%, greenj%, gx%, gy%, redi%, redj%, rx%, ry%, redy%)
      CALL scoreboard(game(), greencount%, redcount%, redwin%, greenwin%)
      CALL ending(greencount%, redcount%, greenwin%, redwin%, continue$)
    END IF

LOOP UNTIL greencount% = 0 OR redcount% = 0

IF continue$ = "n" THEN
   i% = 1000
END IF

NEXT i%

SUB capturegreen (game(), greeni%, greenj%, gx%, gy%, redi%, redj%, rx%, ry%, redy%)

IF game(redy% - 1, redj%) = 2 THEN
   game(redy% - 1, redj%) = 3
   CALL circler(rx%, ry% - 50)
END IF
IF game(redy% + 1, redj%) = 2 THEN
   game(redy% + 1, redj%) = 3
   CALL circler(rx%, ry% + 50)
END IF
IF game(redy%, redj% - 1) = 2 THEN
   game(redy%, redj% - 1) = 3
   CALL circler(rx% - 50, ry%)
END IF
IF game(redy%, redj% + 1) = 2 THEN
   game(redy%, redj% + 1) = 3
   CALL circler(rx% + 50, ry%)
END IF
IF game(redy% + 1, redj% + 1) = 2 THEN
   game(redy% + 1, redj% + 1) = 3
   CALL circler(rx% + 50, ry% + 50)
END IF
IF game(redy% + 1, redj% - 1) = 2 THEN
   game(redy% + 1, redj% - 1) = 3
   CALL circler(rx% - 50, ry% + 50)
END IF
IF game(redy% - 1, redj% + 1) = 2 THEN
   game(redy% - 1, redj% + 1) = 3
   CALL circler(rx% + 50, ry% - 50)
END IF
IF game(redy% - 1, redj% - 1) = 2 THEN
   game(redy% - 1, redj% - 1) = 3
   CALL circler(rx% - 50, ry% - 50)
END IF

END SUB

SUB capturered (game(), greeni%, greenj%, gx%, gy%)
   
IF game(greeni% - 1, greenj%) = 3 THEN
   game(greeni% - 1, greenj%) = 2
   CALL circleg(gx%, gy% - 50)
END IF
IF game(greeni% + 1, greenj%) = 3 THEN
   game(greeni% + 1, greenj%) = 2
   CALL circleg(gx%, gy% + 50)
END IF
IF game(greeni%, greenj% - 1) = 3 THEN
   game(greeni%, greenj% - 1) = 2
   CALL circleg(gx% - 50, gy%)
END IF
IF game(greeni%, greenj% + 1) = 3 THEN
   game(greeni%, greenj% + 1) = 2
   CALL circleg(gx% + 50, gy%)
END IF
IF game(greeni% + 1, greenj% + 1) = 3 THEN
   game(greeni% + 1, greenj% + 1) = 2
   CALL circleg(gx% + 50, gy% + 50)
END IF
IF game(greeni% + 1, greenj% - 1) = 3 THEN
   game(greeni% + 1, greenj% - 1) = 2
   CALL circleg(gx% - 50, gy% + 50)
END IF
IF game(greeni% - 1, greenj% + 1) = 3 THEN
   game(greeni% - 1, greenj% + 1) = 2
   CALL circleg(gx% + 50, gy% - 50)
END IF
IF game(greeni% - 1, greenj% - 1) = 3 THEN
   game(greeni% - 1, greenj% - 1) = 2
   CALL circleg(gx% - 50, gy% - 50)
END IF

END SUB

SUB circleg (gx%, gy%)

CIRCLE (gx%, gy%), 1, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 2, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 3, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 4, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 5, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 6, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 7, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 8, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 9, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 10, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 11, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 12, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 13, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 14, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 15, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 16, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 17, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 18, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 19, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
CIRCLE (gx%, gy%), 20, 2
PAINT (gx%, gy%), 2, 2
CALL pauser
                  
END SUB

SUB circler (rx%, ry%)

CIRCLE (rx%, ry%), 1, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 2, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 3, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 4, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 5, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 6, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 7, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 8, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 9, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 10, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 11, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 12, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 13, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 14, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 15, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 16, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 17, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 18, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 19, 4
PAINT (rx%, ry%), 4, 4
CALL pauser
CIRCLE (rx%, ry%), 20, 4
PAINT (rx%, ry%), 4, 4
CALL pauser

END SUB

SUB ending (greencount%, redcount%, greenwin%, redwin%, continue$)

IF greencount% = 0 THEN
   redwin% = redwin% + 1
   LOCATE 22, 58
   PRINT "Red Victory!"
   LOCATE 28, 2
   INPUT "Would you like to play again? (y/n)"; continue$
ELSEIF redcount% = 0 THEN
   greenwin% = greenwin% + 1
   LOCATE 22, 58
   PRINT "Green Victory!"
   LOCATE 29, 2
   INPUT "Would you like to play again? (y/n)"; continue$
END IF

END SUB

SUB gameboard (i%, j%, x%, y%, game())

FOR i% = 1 TO 8
FOR j% = 1 TO 8
game(i%, j%) = INT(RND * 8) + 1
NEXT j%
NEXT i%

FOR i% = 1 TO 8
y% = 20 + 50 * (i% - 1)

FOR j% = 1 TO 8
x% = 20 + 50 * (j% - 1)

IF game(i%, j%) = 1 THEN
  LINE (x%, y%)-STEP(50, 50), 1, BF
ELSE
  game(i%, j%) = 0
  LINE (x%, y%)-STEP(50, 50), 1, B
END IF

  NEXT j%
NEXT i%

LOCATE 1, 1
PRINT "     1     2     3     4      5     6      7     8  "
LOCATE 3
PRINT "1"
LOCATE 7
PRINT "2"
LOCATE 10
PRINT "3"
LOCATE 13
PRINT "4"
LOCATE 16
PRINT "5"
LOCATE 19
PRINT "6"
LOCATE 22
PRINT "7"
LOCATE 25
PRINT "8"

END SUB

SUB intro

CLS
SCREEN 12

LOCATE 12, 30
PRINT "-----PHAGE FIGHT-----"

LOCATE 20, 31
PRINT "Press 'p' to play"
LOCATE 21, 30
INPUT "Press 'r' for rules ", start$

IF start$ = "r" THEN
   CLS
   LOCATE 1, 30
   PRINT "PHAGE FIGHT"
   LOCATE 6, 1
   PRINT "* This is a game of skill - the object is to occupy the most spaces on the"
   PRINT "gameboard when the game is over."
   PRINT "* The game is over when every square is filled, or there are no more accessable"
   PRINT "squares. "
   PRINT "* When a phage is placed in a square, all phages in adjacent squares become the colour of that phage."
   PRINT "* You determine movement by typing in the x,y co-ordinates of the destination "
   PRINT "square. "

   CALL pauser

   DO
   LOCATE 15, 1
   INPUT "Press 'p' to play! ", key2$
   LOOP UNTIL key2$ = "p"
   
END IF
END SUB

SUB movegreen (game(), greeni%, greenj%, gx%, gy%, key$)

DO

IF game(greeni%, greenj%) = 3 THEN
   key$ = "5"
END IF

madeerror% = 0

IF key$ = "5" THEN
   LOCATE 12, 55
   PRINT "Enter destination square "
   LOCATE 13, 55
   INPUT "co-ordinates (x,y) ", xnumber%, ynumber%
   IF game(ynumber% - 1, xnumber%) = 2 THEN
      greeni% = ynumber%
      greenj% = xnumber%
      gx% = 45 + 50 * (xnumber% - 1)
      gy% = 45 + 50 * (ynumber% - 1)
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
      LOCATE 12, 55
      PRINT "                        "
      LOCATE 13, 55
      PRINT "                        "
   ELSEIF game(ynumber% - 1, xnumber% - 1) = 2 THEN
      greeni% = ynumber%
      greenj% = xnumber%
      gx% = 45 + 50 * (xnumber% - 1)
      gy% = 45 + 50 * (ynumber% - 1)
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
      LOCATE 12, 55
      PRINT "                        "
      LOCATE 13, 55
      PRINT "                        "
   ELSEIF game(ynumber% - 1, xnumber% + 1) = 2 THEN
      greeni% = ynumber%
      greenj% = xnumber%
      gx% = 45 + 50 * (xnumber% - 1)
      gy% = 45 + 50 * (ynumber% - 1)
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
      LOCATE 12, 55
      PRINT "                        "
      LOCATE 13, 55
      PRINT "                        "
   ELSEIF game(ynumber%, xnumber% - 1) = 2 THEN
      greeni% = ynumber%
      greenj% = xnumber%
      gx% = 45 + 50 * (xnumber% - 1)
      gy% = 45 + 50 * (ynumber% - 1)
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
      LOCATE 12, 55
      PRINT "                        "
      LOCATE 13, 55
      PRINT "                        "
   ELSEIF game(ynumber%, xnumber% + 1) = 2 THEN
      greeni% = ynumber%
      greenj% = xnumber%
      gx% = 45 + 50 * (xnumber% - 1)
      gy% = 45 + 50 * (ynumber% - 1)
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
      LOCATE 12, 55
      PRINT "                        "
      LOCATE 13, 55
      PRINT "                        "
   ELSEIF game(ynumber% + 1, xnumber% - 1) = 2 THEN
      greeni% = ynumber%
      greenj% = xnumber%
      gx% = 45 + 50 * (xnumber% - 1)
      gy% = 45 + 50 * (ynumber% - 1)
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
      LOCATE 12, 55
      PRINT "                        "
      LOCATE 13, 55
      PRINT "                        "
   ELSEIF game(ynumber% + 1, xnumber% + 1) = 2 THEN
      greeni% = ynumber%
      greenj% = xnumber%
      gx% = 45 + 50 * (xnumber% - 1)
      gy% = 45 + 50 * (ynumber% - 1)
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
      LOCATE 12, 55
      PRINT "                        "
      LOCATE 13, 55
      PRINT "                        "
   ELSEIF game(ynumber% + 1, xnumber%) = 2 THEN
      greeni% = ynumber%
      greenj% = xnumber%
      gx% = 45 + 50 * (xnumber% - 1)
      gy% = 45 + 50 * (ynumber% - 1)
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
      LOCATE 12, 55
      PRINT "                        "
      LOCATE 13, 55
      PRINT "                        "
   ELSE
      LOCATE 12, 55
      PRINT "                        "
      LOCATE 13, 55
      PRINT "                        "
      madeerror% = 1
   END IF
END IF

IF key$ = "2" THEN
   greeni% = greeni% + 1
   IF game(greeni%, greenj%) = 1 OR greeni% > 8 THEN
      greeni% = greeni% - 1
      madeerror% = 1
      BEEP
   ELSEIF game(greeni%, greenj%) = 2 THEN
      LOCATE 1, 20
      greeni% = greeni% - 1
      madeerror% = 1
      BEEP
   ELSEIF game(greeni%, greenj%) = 3 THEN
      greeni% = greeni% - 1
      madeerror% = 1
      BEEP
   ELSE
      gy% = gy% + 50
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
   END IF
ELSEIF key$ = "4" THEN
   greenj% = greenj% - 1
   IF game(greeni%, greenj%) = 1 OR greenj% < 1 THEN
      greenj% = greenj% + 1
      madeerror% = 1
      BEEP
   ELSEIF game(greeni%, greenj%) = 2 THEN
      LOCATE 1, 20
      greenj% = greenj% + 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 3 THEN
      greenj% = greenj% + 1
      BEEP
      madeerror% = 1
   ELSE
      gx% = gx% - 50
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
   END IF
ELSEIF key$ = "6" THEN
   greenj% = greenj% + 1
   IF game(greeni%, greenj%) = 1 OR greenj% > 8 THEN
      greenj% = greenj% - 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 2 THEN
      LOCATE 1, 20
      greenj% = greenj% - 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 3 THEN
      greenj% = greenj% - 1
      BEEP
      madeerror% = 1
   ELSE
      gx% = gx% + 50
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
   END IF
ELSEIF key$ = "8" THEN
   greeni% = greeni% - 1
   IF game(greeni%, greenj%) = 1 OR greeni% < 1 THEN
      greeni% = greeni% + 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 2 THEN
      LOCATE 1, 20
      greeni% = greeni% + 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 3 THEN
      greeni% = greeni% + 1
      BEEP
      madeerror% = 1
   ELSE
      gy% = gy% - 50
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
   END IF
ELSEIF key$ = "1" THEN
   greeni% = greeni% + 1
   greenj% = greenj% - 1
   IF game(greeni%, greenj%) = 1 OR greeni% > 8 OR greenj% <= 0 THEN
      greeni% = greeni% - 1
      greenj% = greenj% + 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 2 THEN
      greeni% = greeni% - 1
      greenj% = greenj% + 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 3 THEN
      greeni% = greeni% - 1
      greenj% = greenj% + 1
      BEEP
      madeerror% = 1
   ELSE
      gy% = gy% + 50
      gx% = gx% - 50
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
   END IF
ELSEIF key$ = "3" THEN
   greeni% = greeni% + 1
   greenj% = greenj% + 1
   IF game(greeni%, greenj%) = 1 OR greeni% > 8 OR greenj% > 8 THEN
      greeni% = greeni% - 1
      greenj% = greenj% - 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 2 THEN
      greeni% = greeni% - 1
      greenj% = greenj% - 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 3 THEN
      greeni% = greeni% - 1
      greenj% = greenj% - 1
      BEEP
      madeerror% = 1
   ELSE
      gy% = gy% + 50
      gx% = gx% + 50
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
   END IF
ELSEIF key$ = "7" THEN
   greeni% = greeni% - 1
   greenj% = greenj% - 1
   IF game(greeni%, greenj%) = 1 OR greeni% < 1 OR greenj% < 1 THEN
      greeni% = greeni% + 1
      greenj% = greenj% + 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 2 THEN
      greeni% = greeni% + 1
      greenj% = greenj% + 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 3 THEN
      greeni% = greeni% + 1
      greenj% = greenj% + 1
      BEEP
      madeerror% = 1
   ELSE
      gy% = gy% - 50
      gx% = gx% - 50
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
   END IF
ELSEIF key$ = "9" THEN
   greeni% = greeni% - 1
   greenj% = greenj% + 1
   IF game(greeni%, greenj%) = 1 OR greeni% < 1 OR greenj% > 8 THEN
      greeni% = greeni% + 1
      greenj% = greenj% - 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 2 THEN
      greeni% = greeni% + 1
      greenj% = greenj% - 1
      BEEP
      madeerror% = 1
   ELSEIF game(greeni%, greenj%) = 3 THEN
      greeni% = greeni% + 1
      greenj% = greenj% - 1
      BEEP
      madeerror% = 1
   ELSE
      gy% = gy% - 50
      gx% = gx% + 50
      CALL circleg(gx%, gy%)
      game(greeni%, greenj%) = 2
   END IF

END IF

 IF madeerror% = 1 THEN
    DO
      key$ = INKEY$
    LOOP UNTIL key$ <> ""
  END IF
LOOP UNTIL madeerror% <> 1

END SUB

SUB movered (game(), redi%, redj%, rx%, ry%, redy%)

DO

IF game(redy%, redj%) = 2 THEN
   DO
      ranx% = INT(RND * 8) + 1
      rany% = INT(RND * 8) + 1
   LOOP UNTIL game(rany%, ranx%) = 3
   redy% = rany%
   redj% = ranx%
rx% = 45 + 50 * (redj% - 1)
ry% = 45 + 50 * (redy% - 1)

END IF

madeerror% = 0
RANDOMIZE TIMER
r% = INT(RND * 8) + 1
IF r% = 1 THEN
   redy% = redy% + 1
   IF game(redy%, redj%) = 1 OR redy% > 8 THEN
      redy% = redy% - 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 2 THEN
      LOCATE 1, 20
      redy% = redy% - 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 3 THEN
      ry% = ry% + 50
      madeerror% = 1
   ELSE
      ry% = ry% + 50
      CALL circler(rx%, ry%)
      game(redy%, redj%) = 3
   END IF
ELSEIF r% = 2 THEN
   redj% = redj% - 1
   IF game(redy%, redj%) = 1 OR redj% < 1 THEN
      redj% = redj% + 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 2 THEN
      LOCATE 1, 20
      redj% = redj% + 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 3 THEN
      rx% = rx% - 50
      madeerror% = 1
   ELSE
      rx% = rx% - 50
      CALL circler(rx%, ry%)
      game(redy%, redj%) = 3
   END IF
ELSEIF r% = 3 THEN
   redj% = redj% + 1
   IF game(redy%, redj%) = 1 OR redj% > 8 THEN
      redj% = redj% - 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 2 THEN
      LOCATE 1, 20
      redj% = redj% - 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 3 THEN
      rx% = rx% + 50
      madeerror% = 1
   ELSE
      rx% = rx% + 50
      CALL circler(rx%, ry%)
      game(redy%, redj%) = 3
   END IF
ELSEIF r% = 4 THEN
   redy% = redy% - 1
   IF game(redy%, redj%) = 1 OR redy% < 1 THEN
      redy% = redy% + 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 2 THEN
      LOCATE 1, 20
      redy% = redy% + 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 3 THEN
      ry% = ry% - 50
      madeerror% = 1
   ELSE
      ry% = ry% - 50
      CALL circler(rx%, ry%)
      game(redy%, redj%) = 3
   END IF
ELSEIF r% = 5 THEN
   redy% = redy% + 1
   redj% = redj% - 1
   IF game(redy%, redj%) = 1 OR redy% > 8 OR redj% <= 0 THEN
      redy% = redy% - 1
      redj% = redj% + 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 2 THEN
      redy% = redy% - 1
      redj% = redj% + 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 3 THEN
      ry% = ry% + 50
      rx% = rx% - 50
      madeerror% = 1
   ELSE
      ry% = ry% + 50
      rx% = rx% - 50
      CALL circler(rx%, ry%)
      game(redy%, redj%) = 3
   END IF
ELSEIF r% = 6 THEN
   redy% = redy% + 1
   redj% = redj% + 1
   IF game(redy%, redj%) = 1 OR redy% > 8 OR redj% > 8 THEN
      redy% = redy% - 1
      redj% = redj% - 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 2 THEN
      redy% = redy% - 1
      redj% = redj% - 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 3 THEN
      ry% = ry% + 50
      rx% = rx% + 50
      madeerror% = 1
   ELSE
      ry% = ry% + 50
      rx% = rx% + 50
      CALL circler(rx%, ry%)
      game(redy%, redj%) = 3
   END IF
ELSEIF r% = 7 THEN
   redy% = redy% - 1
   redj% = redj% - 1
   IF game(redy%, redj%) = 1 OR redy% < 1 OR redj% < 1 THEN
      redy% = redy% + 1
      redj% = redj% + 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 2 THEN
      redy% = redy% + 1
      redj% = redj% + 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 3 THEN
      ry% = ry% - 50
      rx% = rx% - 50
      madeerror% = 1
   ELSE
      ry% = ry% - 50
      rx% = rx% - 50
      CALL circler(rx%, ry%)
      game(redy%, redj%) = 3
   END IF
ELSEIF key$ = "9" THEN
   redy% = redy% - 1
   redj% = redj% + 1
   IF game(redy%, redj%) = 1 OR redy% < 1 OR redj% > 8 THEN
      redy% = redy% + 1
      redj% = redj% - 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 2 THEN
      redy% = redy% + 1
      redj% = redj% - 1
      madeerror% = 1
   ELSEIF game(redy%, redj%) = 3 THEN
      ry% = ry% - 50
      rx% = rx% + 50
      madeerror% = 1
   ELSE
      ry% = ry% - 50
      rx% = rx% + 50
      CALL circler(rx%, ry%)
      game(redy%, redj%) = 3
   END IF

END IF

LOOP UNTIL madeerror% <> 1

END SUB

SUB pauser

start! = TIMER
DO
LOOP UNTIL (TIMER - start!) > .05

END SUB

SUB scoreboard (game(), greencount%, redcount%, redwin%, greenwin%)

greencount% = 0
redcount% = 0
LINE (450, 220)-(630, 320), 17, B
LINE (540, 220)-(540, 320), 17
LINE (450, 250)-(630, 250), 17
LINE (450, 285)-(630, 285), 17

LOCATE 15, 60
PRINT "Green"
LOCATE 15, 73
PRINT "Red"

FOR i% = 1 TO 8
   FOR j% = 1 TO 8
      IF game(i%, j%) = 2 THEN
         greencount% = greencount% + 1
      ELSEIF game(i%, j%) = 3 THEN
         redcount% = redcount% + 1
      END IF
      
   NEXT j%
   
NEXT i%

LOCATE 17, 58
PRINT "         "
LOCATE 17, 58
PRINT greencount%; "phages"
LOCATE 17, 69
PRINT "         "
LOCATE 17, 69
PRINT redcount%; "phages"

LOCATE 19, 58
PRINT "         "
LOCATE 19, 58
PRINT greenwin%; "wins"
LOCATE 19, 69
PRINT "         "
LOCATE 19, 69
PRINT redwin%; "wins"

END SUB

SUB squaretest (game())

LOCATE 1, 1
PRINT greeni%, greenj%
LOCATE 20, 1
FOR i% = 1 TO 8
FOR j% = 1 TO 8
PRINT game(i%, j%); " ";
NEXT j%
PRINT
NEXT i%

END SUB

SUB startspots (game(), rx%, ry%, redj%, redy%, gx%, gy%, greenj%, greeni%)

REM -----Find Red Phage Starting Spot-----
DO
ranx% = INT(RND * 8) + 1
rany% = INT(RND * 8) + 1
redj% = ranx%
redy% = rany%
LOOP UNTIL game(rany%, ranx%) <> 1
game(rany%, ranx%) = 3
rx% = 45 + 50 * (redj% - 1)
ry% = 45 + 50 * (redy% - 1)
CALL circler(rx%, ry%)

REM -----Find Green Phage Starting Spot-----
DO
ranx% = INT(RND * 8) + 1
rany% = INT(RND * 8) + 1
greenj% = ranx%
greeni% = rany%
LOOP UNTIL game(rany%, ranx%) <> 1 AND game(rany%, ranx%) <> 3
game(rany%, ranx%) = 2
gx% = 45 + 50 * (ranx% - 1)
gy% = 45 + 50 * (rany% - 1)
CALL circleg(gx%, gy%)

END SUB

