Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sayu Board Game
#1
Hello all, 

 Sayu is a 2 player  abstract strategy tile placing game. 

Donald

   




.pdf   Sayu Description.pdf (Size: 41.36 KB / Downloads: 53)

Code: (Select All)
_TITLE "Sayu Tile Game 2022 - Programmed by Donald L. Foster Jr. 2023"

SCREEN _NEWIMAGE(1305, 736, 256)

RANDOMIZE TIMER

_PALETTECOLOR 1, _RGB32(30, 30, 30) '    Board Space Color
_PALETTECOLOR 2, _RGB32(235, 164, 96) '  Tile Color
_PALETTECOLOR 3, _RGB32(154, 74, 6) '    Board Color
_PALETTECOLOR 4, _RGB32(225, 50, 0) '    Player 2 Red Tile
_PALETTECOLOR 5, _RGB32(109, 39, 0) '    Game Info Color
_PALETTECOLOR 6, _RGB32(150, 150, 150) ' Lt Grey Tile Color
_PALETTECOLOR 7, _RGB32(50, 50, 50) '    Dk Grey Tile Color
_PALETTECOLOR 8, _RGB32(255, 215, 0) '   Gold Tile Color

DIM AS _UNSIGNED INTEGER U, V, W, X, Y, Z, X1, X2, X3, X4, X5, X6
DIM AS _UNSIGNED _BYTE Player, Opponent, Tile, Direction, Rotation, TileColor, TilesPlaced, Winner, Converted, Til, Dir, Rot, DirectionArrow, PlayerScore(2)
DIM AS _UNSIGNED _BIT RandomTiles, Selected, Playable(7, 7), AvailablePattern(7), AvailableTile(7, 8)
DIM AS _UNSIGNED _BYTE PlayerColor(3), PlayerPieces(2), BoardPlayer(7, 7), BoardTile(7, 7), BoardDirection(7, 7), BoardRotation(7, 7), ConvertZ(8), ConvertY(8), DirectionArrow(8, 8)
DIM AS _UNSIGNED INTEGER BoardX(7, 7), BoardY(7, 7), PatternX(7), PatternY(7), TileX(8), TileY(8)

Player = 1: Opponent = 2: TilesPlaced = 1: PlayerScore(1) = 0: PlayerScore(2) = 1
PlayerColor(1) = 0: PlayerColor(2) = 4: PlayerColor(3) = 7: PlayerPieces(1) = 0: PlayerPieces(2) = 0
BoardPlayer(4, 4) = 2: BoardTile(4, 4) = 1: BoardDirection(4, 4) = 0: BoardRotation(4, 4) = 1

' Set Available Tiles to 1
FOR Z = 2 TO 7: AvailablePattern(Z) = 1: FOR Y = 1 TO 8: AvailableTile(Z, Y) = 1: NEXT: NEXT

' Setup Tile PatternX and {atternY
Tile = 2: X = 440: FOR Z = 1 TO 2: V = 899: FOR Y = 1 TO 3: PatternX(Tile) = V: PatternY(Tile) = X: Tile = Tile + 1: V = V + 122: NEXT: X = X + 123: NEXT

' Setup TileX and TileY
Direction = 1: X = 440: FOR Z = 1 TO 2: V = 840: FOR Y = 1 TO 4: TileX(Direction) = V: TileY(Direction) = X: Direction = Direction + 1: V = V + 122: NEXT: X = X + 123: NEXT

'Setup Directiona Arrows
X = 1: FOR Z = 1 TO 8: FOR Y = 1 TO 8: DirectionArrow(Z, Y) = VAL(MID$("12345678 23456781 34567812 45678123 56781234 67812345 78123456 81234567", X, 1)): X = X + 1: NEXT: X = X + 1: NEXT

Tile$ = "TA0BU51L21TA45L42TA90L42TA135L42TA180L42TA225L42TA270L42TA315L42TA360L22"
TileCenter$ = "TA0BU29L12TA45L24TA90L24TA135L24TA180L24TA225L24TA270L24TA315L24TA360L16"
DirectionArrow$ = "C15BD15BR1R2U18F6E4H13G13F4E6D18R3BU2P15,15"
Arrow$(1) = "C0BU30BR2R1U7F2E2H7G7F2E2D7BR2BU2P0,0": Arrow$(2) = "C4BU30BR2R1U7F2E2H7G7F2E2D7BR2BU2P4,4": Arrow$(3) = "C7BU30BR2R1U7F2E2H7G7F2E2D7BR2BU2P7,7"

PieceColor$(1) = "C0": PieceColor$(2) = "C4": PieceColor$(3) = "C7": PieceColor$(4) = "C15"
Direction$(1) = "TA0": Direction$(2) = "TA315": Direction$(3) = "TA270": Direction$(4) = "TA225": Direction$(5) = "TA180": Direction$(6) = "TA135": Direction$(7) = "TA90": Direction$(8) = "TA45"

Tile$(1, 1) = "00000000"
Tile$(2, 1) = "10100010": Tile$(2, 2) = "01010001": Tile$(2, 3) = "10101000": Tile$(2, 4) = "01010100": Tile$(2, 5) = "00101010": Tile$(2, 6) = "00010101": Tile$(2, 7) = "10001010": Tile$(2, 8) = "01000101"
Tile$(3, 1) = "10010100": Tile$(3, 2) = "01001010": Tile$(3, 3) = "00100101": Tile$(3, 4) = "10010010": Tile$(3, 5) = "01001001": Tile$(3, 6) = "10100100": Tile$(3, 7) = "01010010": Tile$(3, 8) = "00101001"
Tile$(4, 1) = "11000010": Tile$(4, 2) = "01100001": Tile$(4, 3) = "10110000": Tile$(4, 4) = "01011000": Tile$(4, 5) = "00101100": Tile$(4, 6) = "00010110": Tile$(4, 7) = "00001011": Tile$(4, 8) = "10000101"
Tile$(5, 1) = "11000100": Tile$(5, 2) = "01100010": Tile$(5, 3) = "00110001": Tile$(5, 4) = "10011000": Tile$(5, 5) = "01001100": Tile$(5, 6) = "00100110": Tile$(5, 7) = "00010011": Tile$(5, 8) = "10001001"
Tile$(6, 1) = "11001000": Tile$(6, 2) = "01100100": Tile$(6, 3) = "00110010": Tile$(6, 4) = "00011001": Tile$(6, 5) = "10001100": Tile$(6, 6) = "01000110": Tile$(6, 7) = "00100011": Tile$(6, 8) = "10011000"
Tile$(7, 1) = "11010000": Tile$(7, 2) = "01101000": Tile$(7, 3) = "00110100": Tile$(7, 4) = "00011010": Tile$(7, 5) = "00001101": Tile$(7, 6) = "10000110": Tile$(7, 7) = "01000011": Tile$(7, 8) = "10100001"

LINE (0, 0)-(737, 736), 3, BF: LINE (738, 0)-(1305, 736), 5, BF

' Draw Board
X = 59
FOR Z = 1 TO 7
   V = 59
   FOR Y = 1 TO 7
      IF BoardPlayer(Z, Y) THEN X1 = V: X2 = X: X3 = 2: X4 = 0: GOSUB DrawTile
      BoardX(Z, Y) = V: BoardY(Z, Y) = X
      V = V + 104
   NEXT
   X = X + 103
NEXT

COLOR 15, 5: LOCATE 2, 108: PRINT "S  A  Y  U     B  O  A  R  D    g  A  M  E";

LOCATE 10, 115: PRINT "Choose Tiles Randomly?  Y or N";
GetRandom: A$ = UCASE$(INKEY$): IF A$ = "" GOTO GetRandom
IF ASC(A$) = 27 AND FullScreen = 0 THEN FullScreen = -1: _FULLSCREEN _SQUAREPIXELS , _SMOOTH ELSE IF ASC(A$) = 27 THEN FullScreen = 0: _FULLSCREEN _OFF
IF A$ = "Y" THEN RandomTiles = 1 ELSE IF A$ = "N" THEN RandomTiles = 0 ELSE GOTO GetRandom

LOCATE 10, 115: PRINT "                              ";

StartGame:
' Show Player Indicator
X1 = 1021: X2 = 115: X3 = Player: X4 = 1: X5 = 1: X6 = 1: GOSUB DrawTile
COLOR 15, 5: LOCATE 13, 124: PRINT "Player: "; Player;

' Display Player's Tiles Count
LOCATE 41, 108: PRINT "Player 1's Tiles:"; PlayerScore(1);
LOCATE 41, 132: PRINT "Player 2's Tiles:"; PlayerScore(2);

' Set Playable Spaces to 0
FOR Z = 1 TO 7: FOR Y = 1 TO 7: Playable(Z, Y) = 0: NEXT: NEXT

' Get Playable Board Spaces
FOR Z = 1 TO 7
   FOR Y = 1 TO 7
      IF BoardPlayer(Z, Y) THEN
         IF Z - 1 >= 1 THEN IF BoardPlayer(Z - 1, Y) = 0 THEN Playable(Z - 1, Y) = 1
         IF Z + 1 <= 7 THEN IF BoardPlayer(Z + 1, Y) = 0 THEN Playable(Z + 1, Y) = 1
         IF Y - 1 >= 1 THEN IF BoardPlayer(Z, Y - 1) = 0 THEN Playable(Z, Y - 1) = 1
         IF Y + 1 <= 7 THEN IF BoardPlayer(Z, Y + 1) = 0 THEN Playable(Z, Y + 1) = 1
      END IF
   NEXT
NEXT

' Get Available Tile Patterns
FOR Z = 2 TO 7
   X = 0
   FOR Y = 1 TO 8
      IF AvailableTile(Z, Y) THEN X = 1
   NEXT
   IF X THEN AvailablePattern(Z) = 1 ELSE AvailablePattern(Z) = 0
NEXT

IF RandomTiles THEN
   RandomTile: Tile = INT(RND * 6) + 2: Direction = INT(RND * 8) + 1
   IF AvailableTile(Tile, Direction) = 0 GOTO RandomTile
   GOTO ChooseTileRotation
END IF

ShowTilePatterns:
LINE (780, 230)-(1270, 630), 5, BF

' Show Player's Available Tile Patterns
FOR Tile = 2 TO 7
   IF AvailablePattern(Tile) THEN X3 = Player ELSE X3 = 3
   X1 = PatternX(Tile): X2 = PatternY(Tile): X4 = Tile: X5 = 0: X6 = 1: GOSUB DrawTile
NEXT

ChooseTilePattern:
LOCATE 45, 108: PRINT " Choose an Available Tile Pattern to Play ";

GetTilePattern:
DO WHILE _MOUSEINPUT
   Tile = 2
   FOR Z = 1 TO 2
      FOR Y = 1 TO 3
         IF _MOUSEX > PatternX(Tile) - 60 AND _MOUSEX < PatternX(Tile) + 60 AND _MOUSEY > PatternY(Tile) - 60 AND _MOUSEY < PatternY(Tile) + 60 AND AvailablePattern(Tile) THEN Selected = 1 ELSE Selected = 0
         IF Selected THEN
            LINE (PatternX(Tile) - 60, PatternY(Tile) - 60)-(PatternX(Tile) + 60, PatternY(Tile) + 60), 15, B
         ELSE
            LINE (PatternX(Tile) - 60, PatternY(Tile) - 60)-(PatternX(Tile) + 60, PatternY(Tile) + 60), 5, B
         END IF
         IF _MOUSEBUTTON(1) AND Selected THEN GOSUB ReleaseButton: GOTO ChooseTileDirection
         Tile = Tile + 1
      NEXT
   NEXT
LOOP
A$ = INKEY$: IF A$ <> "" THEN IF ASC(A$) = 27 AND FullScreen = 0 THEN FullScreen = -1: _FULLSCREEN _SQUAREPIXELS , _SMOOTH ELSE IF ASC(A$) = 27 THEN FullScreen = 0: _FULLSCREEN _OFF
GOTO GetTilePattern

ChooseTileDirection:
LINE (770, 230)-(1280, 630), 5, BF
X1 = 1021: X2 = 300: X3 = Player: X4 = Tile: X5 = 0: X6 = 1: GOSUB DrawTile

' Show Player's Available Tiles
FOR Direction = 1 TO 8
   IF AvailableTile(Tile, Direction) THEN X3 = Player ELSE X3 = 3
   X1 = TileX(Direction): X2 = TileY(Direction): X4 = Tile: X5 = Direction: X6 = 1: GOSUB DrawTile
NEXT

LOCATE 45, 108: PRINT "Choose an Available Tile Direction to Play";

GetTileDirection:
DO WHILE _MOUSEINPUT

   ' Choose a Different Tile Pattern
   IF _MOUSEX > 968 AND _MOUSEX < 1074 AND _MOUSEY > 243 AND _MOUSEY < 353 THEN Selected = 1 ELSE Selected = 0
   IF Selected THEN
      LINE (961, 240)-(1081, 360), 15, B
   ELSE
      LINE (961, 240)-(1081, 360), 5, B
   END IF
   IF _MOUSEBUTTON(1) AND Selected THEN GOSUB ReleaseButton: GOTO ShowTilePatterns

   ' Choose Tile Direction
   FOR Direction = 1 TO 8
      IF _MOUSEX > TileX(Direction) - 60 AND _MOUSEX < TileX(Direction) + 60 AND _MOUSEY > TileY(Direction) - 60 AND _MOUSEY < TileY(Direction) + 60 AND AvailableTile(Tile, Direction) THEN Selected2 = 1 ELSE Selected2 = 0
      IF Selected2 = 1 THEN
         LINE (TileX(Direction) - 60, TileY(Direction) - 60)-(TileX(Direction) + 60, TileY(Direction) + 60), 15, B
      ELSE
         LINE (TileX(Direction) - 60, TileY(Direction) - 60)-(TileX(Direction) + 60, TileY(Direction) + 60), 5, B
      END IF
      IF _MOUSEBUTTON(1) AND Selected2 THEN GOSUB ReleaseButton: GOTO ChooseTileRotation
   NEXT

LOOP
A$ = INKEY$: IF A$ <> "" THEN IF ASC(A$) = 27 AND FullScreen = 0 THEN FullScreen = -1: _FULLSCREEN _SQUAREPIXELS , _SMOOTH ELSE IF ASC(A$) = 27 THEN FullScreen = 0: _FULLSCREEN _OFF
GOTO GetTileDirection

ChooseTileRotation:
LINE (770, 230)-(1280, 630), 5, BF
X1 = 1021: X2 = 300: X3 = Player: X4 = Tile: X5 = Direction: X6 = 1: GOSUB DrawTile

' Remove Playable Board Spaces from View
FOR Z = 1 TO 7
   FOR Y = 1 TO 7
      IF Playable(Z, Y) THEN PSET (BoardX(Z, Y), BoardY(Z, Y)), 3: DRAW Tile$
   NEXT
NEXT

' Show Tile Rotations
FOR Rotation = 1 TO 8: X1 = TileX(Rotation): X2 = TileY(Rotation): X3 = Player: X4 = Tile: X5 = Direction: X6 = Rotation: GOSUB DrawTile: NEXT

LOCATE 45, 108: PRINT "      Choose a Tile Rotationn to Play     ";

GetTileRotation:
DO WHILE _MOUSEINPUT

   ' Choose a Different Tile Direction
   IF RandomTiles = 0 THEN
      IF _MOUSEX > 968 AND _MOUSEX < 1074 AND _MOUSEY > 243 AND _MOUSEY < 353 THEN Selected = 1 ELSE Selected = 0
      IF Selected THEN
         LINE (961, 240)-(1081, 360), 15, B
      ELSE
         LINE (961, 240)-(1081, 360), 5, B
      END IF
      IF _MOUSEBUTTON(1) AND Selected THEN GOSUB ReleaseButton: GOTO ChooseTileDirection
   END IF

   ' Choose Tile Rotation
   FOR Rotation = 1 TO 8
      IF _MOUSEX > TileX(Rotation) - 60 AND _MOUSEX < TileX(Rotation) + 60 AND _MOUSEY > TileY(Rotation) - 60 AND _MOUSEY < TileY(Rotation) + 60 THEN Selected = 1 ELSE Selected = 0
      IF Selected THEN
         LINE (TileX(Rotation) - 60, TileY(Rotation) - 60)-(TileX(Rotation) + 60, TileY(Rotation) + 60), 15, B
      ELSE
         LINE (TileX(Rotation) - 60, TileY(Rotation) - 60)-(TileX(Rotation) + 60, TileY(Rotation) + 60), 5, B
      END IF
      IF _MOUSEBUTTON(1) AND Selected THEN GOSUB ReleaseButton: GOTO ChooseBoardSpace
   NEXT

LOOP
A$ = INKEY$: IF A$ <> "" THEN IF ASC(A$) = 27 AND FullScreen = 0 THEN FullScreen = -1: _FULLSCREEN _SQUAREPIXELS , _SMOOTH ELSE IF ASC(A$) = 27 THEN FullScreen = 0: _FULLSCREEN _OFF
GOTO GetTileRotation

ChooseBoardSpace:
LINE (770, 230)-(1280, 630), 5, BF
X1 = 1021: X2 = 300: X3 = Player: X4 = Tile: X5 = Direction: X6 = Rotation: GOSUB DrawTile

' Show Playable Board Spaces
FOR Z = 1 TO 7
   FOR Y = 1 TO 7
      IF Playable(Z, Y) THEN PSET (BoardX(Z, Y), BoardY(Z, Y)), 3: DRAW "C15" + Tile$
   NEXT
NEXT

LOCATE 45, 108: PRINT "     Choose a Board Space to Play Tile    ";

GetBoardSpace:
DO WHILE _MOUSEINPUT

   ' Choose a Different Tile Rotation
   IF _MOUSEX > 968 AND _MOUSEX < 1074 AND _MOUSEY > 243 AND _MOUSEY < 353 THEN Selected = 1 ELSE Selected = 0
   IF Selected THEN
      LINE (961, 240)-(1081, 360), 15, B
   ELSE
      LINE (961, 240)-(1081, 360), 5, B
   END IF
   IF _MOUSEBUTTON(1) AND Selected THEN GOSUB ReleaseButton: GOTO ChooseTileRotation

   ' Choose a Board Space
   FOR Z = 1 TO 7
      FOR Y = 1 TO 7
         IF _MOUSEX > BoardX(Z, Y) - 55 AND _MOUSEX < BoardX(Z, Y) + 55 AND _MOUSEY > BoardY(Z, Y) - 55 AND _MOUSEY < BoardY(Z, Y) + 55 AND _MOUSEBUTTON(1) THEN GOSUB ReleaseButton: GOTO PlaceTile
      NEXT
   NEXT

LOOP
A$ = INKEY$: IF A$ <> "" THEN IF ASC(A$) = 27 AND FullScreen = 0 THEN FullScreen = -1: _FULLSCREEN _SQUAREPIXELS , _SMOOTH ELSE IF ASC(A$) = 27 THEN FullScreen = 0: _FULLSCREEN _OFF
GOTO GetBoardSpace

PlaceTile:
LINE (770, 230)-(1280, 630), 5, BF

' Nove Tile to Board Space
BoardPlayer(Z, Y) = Player: BoardTile(Z, Y) = Tile: BoardDirection(Z, Y) = Direction: BoardRotation(Z, Y) = Rotation: BoardTile$(Z, Y) = Tile$(Tile, Rotation)
AvailableTile(Tile, Direction) = 0: Playable(Z, Y) = 0: X1 = BoardX(Z, Y): X2 = BoardY(Z, Y): X3 = Player: X4 = Tile: X5 = Direction: X6 = Rotation: GOSUB DrawTile

' Remove Playaable Cursors from the Board
FOR V = 1 TO 7
   FOR W = 1 TO 7
      IF Playable(V, W) THEN PSET (BoardX(V, W), BoardY(V, W)), 3: DRAW "C3" + Tile$
   NEXT
NEXT

CheckTilesConvert: Converted = 0: DirectionArrow = DirectionArrow(Direction, Rotation)

' Set Playables to 0
FOR V = 1 TO 7
   FOR W = 1 TO 7
      IF Playable(V, W) THEN Playable(V, W) = 0
   NEXT
NEXT

' Check Up
IF Z - 1 >= 1 THEN
   Til = BoardTile(Z - 1, Y): Dir = BoardDirection(Z - 1, Y): Rot = BoardRotation(Z - 1, Y)
   IF BoardPlayer(Z - 1, Y) = Opponent AND DirectionArrow(Dir, Rot) <> DirectionArrow AND MID$(Tile$(Tile, Rotation), 1, 1) = "1" AND MID$(Tile$(BoardTile(Z - 1, Y), Rot), 5, 1) = "0" THEN
      Converted = Converted + 1: Playable(Z - 1, Y) = 1
   END IF
END IF

' Check Down
IF Z + 1 <= 7 THEN
   Til = BoardTile(Z + 1, Y): Dir = BoardDirection(Z + 1, Y): Rot = BoardRotation(Z + 1, Y)
   IF BoardPlayer(Z + 1, Y) = Opponent AND DirectionArrow(Dir, Rot) <> DirectionArrow AND MID$(Tile$(Tile, Rotation), 5, 1) = "1" AND MID$(Tile$(BoardTile(Z + 1, Y), Rot), 1, 1) = "0" THEN
      Converted = Converted + 1: Playable(Z + 1, Y) = 1
   END IF
END IF

' Check Left
IF Y - 1 >= 1 THEN
   Til = BoardTile(Z, Y - 1): Dir = BoardDirection(Z, Y - 1): Rot = BoardRotation(Z, Y - 1)
   IF BoardPlayer(Z, Y - 1) = Opponent AND DirectionArrow(Dir, Rot) <> DirectionArrow AND MID$(Tile$(Tile, Rotation), 7, 1) = "1" AND MID$(Tile$(BoardTile(Z, Y - 1), Rot), 3, 1) = "0" THEN
      Converted = Converted + 1: Playable(Z, Y - 1) = 1
   END IF
END IF

' Check Right
IF Y + 1 <= 7 THEN
   Til = BoardTile(Z, Y + 1): Dir = BoardDirection(Z, Y + 1): Rot = BoardRotation(Z, Y + 1)
   IF BoardPlayer(Z, Y + 1) = Opponent AND DirectionArrow(Dir, Rot) <> DirectionArrow AND MID$(Tile$(Tile, Rotation), 3, 1) = "1" AND MID$(Tile$(BoardTile(Z, Y + 1), Rot), 7, 1) = "0" THEN
      Converted = Converted + 1: Playable(Z, Y + 1) = 1
   END IF
END IF

' Check Up Left
IF Z - 1 >= 1 AND Y - 1 >= 1 THEN
   IF BoardPlayer(Z - 1, Y - 1) = Opponent AND DirectionArrow(BoardDirection(Z - 1, Y - 1), BoardRotation(Z - 1, Y - 1)) <> DirectionArrow THEN
      IF MID$(Tile$(Tile, Rotation), 8, 1) = "1" AND MID$(Tile$(BoardTile(Z - 1, Y - 1), BoardRotation(Z - 1, Y - 1)), 4, 1) = "0" THEN
         Converted = Converted + 1: Playable(Z - 1, Y - 1) = 1
      END IF
   END IF
END IF

' Check Up Right
IF Z - 1 >= 1 AND Y + 1 <= 7 THEN
   IF BoardPlayer(Z - 1, Y + 1) = Opponent AND DirectionArrow(BoardDirection(Z - 1, Y + 1), BoardRotation(Z - 1, Y + 1)) <> DirectionArrow THEN
      IF MID$(Tile$(Tile, Rotation), 2, 1) = "1" AND MID$(Tile$(BoardTile(Z - 1, Y + 1), BoardRotation(Z - 1, Y + 1)), 6, 1) = "0" THEN
         Converted = Converted + 1: Playable(Z - 1, Y + 1) = 1
      END IF
   END IF
END IF

' Check Down Left
IF Z + 1 <= 7 AND Y - 1 >= 1 THEN
   IF BoardPlayer(Z + 1, Y - 1) = Opponent AND DirectionArrow(BoardDirection(Z + 1, Y - 1), BoardRotation(Z + 1, Y - 1)) <> DirectionArrow THEN
      IF MID$(Tile$(Tile, Rotation), 6, 1) = "1" AND MID$(Tile$(BoardTile(Z + 1, Y - 1), BoardRotation(Z + 1, Y - 1)), 2, 1) = "0" THEN
         Converted = Converted + 1: Playable(Z + 1, Y - 1) = 1
      END IF
   END IF
END IF

' Check Down Right
IF Z + 1 <= 7 AND Y + 1 <= 7 THEN
   IF BoardPlayer(Z + 1, Y + 1) = Opponent AND DirectionArrow(BoardDirection(Z + 1, Y + 1), BoardRotation(Z + 1, Y + 1)) <> DirectionArrow THEN
      IF MID$(Tile$(Tile, Rotation), 4, 1) = "1" AND MID$(Tile$(BoardTile(Z + 1, Y + 1), BoardRotation(Z + 1, Y + 1)), 8, 1) = "0" THEN
         Converted = Converted + 1: Playable(Z + 1, Y + 1) = 1
      END IF
   END IF
END IF

IF Converted THEN

   ' Highlight Placed or Newly Convert Tile to Gold
   PAINT (BoardX(Z, Y), BoardY(Z, Y) - 47), 8, PlayerColor(Player)

   ' Highlight Tile(s) to be Converted to White
   FOR X = 1 TO 7
      FOR V = 1 TO 7
         IF Playable(X, V) THEN PAINT (BoardX(X, V), BoardY(X, V) - 47), 15, PlayerColor(Opponent)
      NEXT
   NEXT

   ' Check for Multiple Converable Tiles
   IF Converted > 1 THEN
      LOCATE 43, 113: PRINT "Multiple Tiles Can be Converted";
      LOCATE 45, 108: PRINT "         Choose a Tile to Convert         ";

      ChooseConvertedTile:
      DO WHILE _MOUSEINPUT
         FOR X = 1 TO 7: FOR V = 1 TO 7
            IF _MOUSEX > BoardX(X, V) - 55 AND _MOUSEX < BoardX(X, V) + 55 AND _MOUSEY > BoardY(X, V) - 55 AND _MOUSEY < BoardY(X, V) + 55 AND _MOUSEBUTTON(1) AND Playable(X, V) THEN
               GOSUB ReleaseButton: GOTO RestoreTiles
               END IF
            NEXT
         NEXT
      LOOP
      A$ = INKEY$: IF A$ <> "" THEN IF ASC(A$) = 27 AND FullScreen = 0 THEN FullScreen = -1: _FULLSCREEN _SQUAREPIXELS , _SMOOTH ELSE IF ASC(A$) = 27 THEN FullScreen = 0: _FULLSCREEN _OFF
      GOTO ChooseConvertedTile

      RestoreTiles:

      LOCATE 43, 113: PRINT "                                 ";

      ' Set Tile Not Being Converted Back to Tile Color
      Playable(X, V) = 0
      FOR W = 1 TO 7
         FOR U = 1 TO 7
            IF Playable(W, U) = 1 THEN PAINT (BoardX(W, U), BoardY(W, U) - 47), 2, PlayerColor(Opponent)
         NEXT
      NEXT

      GOTO ConvertTile

   ELSE

      ' Get Tile to be Converted
      FOR W = 1 TO 7
         FOR U = 1 TO 7
            IF Playable(W, U) THEN X = W: V = U
         NEXT
      NEXT

   END IF

   LOCATE 45, 108: PRINT "     Press <ENTER> to Contvert Tile(s)     ";

   GetENTER1: A$ = INKEY$: IF A$ = "" GOTO GetENTER1
   IF ASC(A$) = 27 AND FullScreen = 0 THEN FullScreen = -1: _FULLSCREEN _SQUAREPIXELS , _SMOOTH ELSE IF ASC(A$) = 27 THEN FullScreen = 0: _FULLSCREEN _OFF
   IF ASC(A$) <> 13 GOTO GetENTER1

   ' Remove Tile to be Converted from Screen
   ConvertTile: PAINT (BoardX(X, V), BoardY(X, V)), 3

   ' Get New Rotation of Tile to be Converted
   Til = BoardTile(X, V): Dir = BoardDirection(X, V): Rot = BoardRotation(X, V)
   RotateTile: IF Til = 1 THEN Dir = 0: GOTO DisplayTile
   IF DirectionArrow(Dir, Rot) = DirectionArrow GOTO DisplayTile
   IF Rot = 8 THEN Rot = 1 ELSE Rot = Rot + 1
   GOTO RotateTile

   ' Display the Converted Tile
   DisplayTile: X1 = BoardX(X, V): X2 = BoardY(X, V): X3 = Player: X4 = Til: X5 = Dir: X6 = Rot: GOSUB DrawTile

   ' Update Converted Tile Board Info
   BoardPlayer(X, V) = Player: BoardRotation(X, V) = Rot: BoardTile$(X, V) = Tile$(Til, Rot)

   ' Change Placed or Converted Tile Back to Player Color
   PAINT (BoardX(Z, Y), BoardY(Z, Y) - 47), 2, PlayerColor(Player)

   Z = X: Y = V: Tile = BoardTile(Z, Y): Direction = BoardDirection(Z, Y): Rotation = BoardRotation(Z, Y)

   GOTO CheckTilesConvert
END IF

TilesPlaced = TilesPlaced + 1

' Calculate Player's Score
PlayerScore(1) = 0: PlayerScore(2) = 0
FOR Z = 1 TO 7
   FOR Y = 1 TO 7
      IF BoardPlayer(Z, Y) THEN PlayerScore(BoardPlayer(Z, Y)) = PlayerScore(BoardPlayer(Z, Y)) + 1
   NEXT
NEXT

' Check for End of Game and Declare Winner
IF TilesPlaced = 49 THEN
   FOR Z = 1 TO 7: FOR Y = 1 TO 7: PlayerPieces(BoardPlayer(Z, Y)) = PlayerPieces(BoardPlayer(Z, Y)) + 1: NEXT: NEXT
   IF PlayerPieces(1) > PlayerPieces(2) THEN Winner = 1 ELSE Winner = 2

   ' Display Player's Tiles Count
   LOCATE 41, 108: PRINT "Player 1's Score:"; PlayerScore(1);
   LOCATE 41, 132: PRINT "Player 2's Score:"; PlayerScore(2);

   X1 = 1021: X2 = 115: X3 = Winner: X4 = 1: X5 = 1: X6 = 1: GOSUB DrawTile
   LOCATE 43, 118: PRINT "Player"; Winner; "is the Winner!";
   LOCATE 45, 108: PRINT "        Play Another Game?  Y or N        ";

   Winner: A$ = UCASE$(INKEY$): IF A$ = "" GOTO Winner
   IF ASC(A$) = 27 AND FullScreen = 0 THEN FullScreen = -1: _FULLSCREEN _SQUAREPIXELS , _SMOOTH ELSE IF ASC(A$) = 27 THEN FullScreen = 0: _FULLSCREEN _OFF
   IF A$ = "Y" THEN RUN ELSE IF A$ = "N" THEN SYSTEM ELSE GOTO Winner
END IF

IF convertz = 4 AND converty = 4 THEN BoardTile(4, 4) = 1: BoardDirection(4, 4) = 0: BoardRotation(4, 4) = 1

SWAP Player, Opponent: GOTO StartGame

ReleaseButton:
DO WHILE _MOUSEINPUT
   IF _MOUSEBUTTON(1) = 0 THEN RETURN
LOOP
GOTO ReleaseButton

DrawTile:
' X1 = Screen X Position
' X2 = Screen Y Position
' X3 = Player, 3 = Tile and/or Tile Pattern Not Available
' X4 = Tile
' X5 = Direction
' X6 = Rotation
IF X3 = 3 THEN TileColor = 6 ELSE TileColor = 2
PSET (X1, X2), 3: DRAW PieceColor$(X3) + Tile$: PAINT (X1, X2), TileColor, PlayerColor(X3)
PSET (X1, X2), TileColor: DRAW PieceColor$(X3) + TileCenter$: PAINT (X1, X2), PlayerColor(X3)
FOR W = 1 TO 8
   U = VAL(MID$(Tile$(X4, X6), W, 1)): IF U THEN PSET (X1, X2), PlayerColor(X3): DRAW Direction$(W) + Arrow$(X3)
NEXT
IF X4 > 1 THEN DirectionArrow = DirectionArrow(X5, X6) ELSE DirectionArrow = 0
IF DirectionArrow THEN PSET (X1, X2), PlayerColor(X3): DRAW Direction$(DirectionArrow) + DirectionArrow$
RETURN
Reply
#2
Nicely done. I had to see the video and the PDF to understand the game.

Probably you can do an AI player for this next.
Reply
#3
Hi, thanks for checking out my game. An A.I. player is a great idea. however, I never learned or completely understood how to A.I. done. I've seen books and articles on the subject, but I'm just not catching on. All of my games are human players only. Maybe some day I'll learn it.

Donald
Reply
#4
(06-09-2023, 03:05 AM)a740g Wrote: Nicely done. I had to see the video and the PDF to understand the game.

Probably you can do an AI player for this next.
+1 I've been saying this all along with Donald's board games.

If just 20% of them had AI, theyd be a really great hit!  Multi-player board games might work on Internet?

@Donald Foster Allot of AI is about analysing "the state of a board" and assigning a numerical score. Then for AI it would try all possible moves and see which came back with highest score. Before that would be a subroutine that sees a player has won. Try it on Tic Tac Toe or Connect 4.
b = b + ...
Reply
#5
(06-09-2023, 04:27 PM)bplus Wrote:
(06-09-2023, 03:05 AM)a740g Wrote: Nicely done. I had to see the video and the PDF to understand the game.

Probably you can do an AI player for this next.
+1 I've been saying this all along with Donald's board games.

If just 20% of them had AI, theyd be a really great hit!  Multi-player board games might work on Internet?

@Donald Foster Allot of AI is about analysing "the state of a board" and assigning a numerical score. Then for AI it would try all possible moves and see which came back with highest score. Before that would be a subroutine that sees a player has won. Try it on Tic Tac Toe or Connect 4.
These are called minmax algorithms: https://en.wikipedia.org/wiki/Minimax

They are a bear to implement because of their recursive nature but work very well for board games.
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply
#6
(06-09-2023, 04:27 PM)bplus Wrote:
(06-09-2023, 03:05 AM)a740g Wrote: Nicely done. I had to see the video and the PDF to understand the game.

Probably you can do an AI player for this next.
+1 I've been saying this all along with Donald's board games.

If just 20% of them had AI, theyd be a really great hit!  Multi-player board games might work on Internet?

@Donald Foster Allot of AI is about analysing "the state of a board" and assigning a numerical score. Then for AI it would try all possible moves and see which came back with highest score. Before that would be a subroutine that sees a player has won. Try it on Tic Tac Toe or Connect 4.

Thanks for the advice bplus. I guess when it comes to A.I., I've been nervous about getting my feet wet. Maybe, I should just dive in and see what happens. 

Also, I have been wanting to make multiplayer games for a long time, but don't have enough knowledge. This goes all the way back to the TRS-80 Model III / Model 4 days when I first started making games. I knew about using a null modem to connect 2 computers together. But, I hadn't learned network programming and still don't. It would have been great back then when I made my Battleship and Stratego board games. There are a lot of games, including card games, that keeps components consealed from other players. Even an internet or WIFI game would be great to learn. Another good iea is using 1 computer with dual monitors and dual mouse. Again, I have no knowledge on writing code using dual monitors. Maybe there is or someone could make good tutorial on these topics.
Reply
#7
(06-09-2023, 05:09 PM)Donald Foster Wrote:
(06-09-2023, 04:27 PM)bplus Wrote:
(06-09-2023, 03:05 AM)a740g Wrote: Nicely done. I had to see the video and the PDF to understand the game.

Probably you can do an AI player for this next.
+1 I've been saying this all along with Donald's board games.

If just 20% of them had AI, theyd be a really great hit!  Multi-player board games might work on Internet?

@Donald Foster Allot of AI is about analysing "the state of a board" and assigning a numerical score. Then for AI it would try all possible moves and see which came back with highest score. Before that would be a subroutine that sees a player has won. Try it on Tic Tac Toe or Connect 4.

Thanks for the advice bplus. I guess when it comes to A.I., I've been nervous about getting my feet wet. Maybe, I should just dive in and see what happens. 

Also, I have been wanting to make multiplayer games for a long time, but don't have enough knowledge. This goes all the way back to the TRS-80 Model III / Model 4 days when I first started making games. I knew about using a null modem to connect 2 computers together. But, I hadn't learned network programming and still don't. It would have been great back then when I made my Battleship and Stratego board games. There are a lot of games, including card games, that keeps components consealed from other players. Even an internet or WIFI game would be great to learn. Another good iea is using 1 computer with dual monitors and dual mouse. Again, I have no knowledge on writing code using dual monitors. Maybe there is or someone could make good tutorial on these topics.
Yeah the road in the woods diverges, 
1 way is multi-player on Internet, I can't help with that but there are people here who can, @SMcNeill I am pretty sure or @a740g seems pretty good in tech dept or @grymmjack but we have him pretty busy already ;-))

I might help with AI and recursion (my favorite trick! it's so cool when it works!) but you will have to figure your own way to assigning score to any given "board state" for any given game.

I will look up my Connect 4 thingy with AI doesn't play a perfect game but will be pretty good frustrator ;-))

Oh yeah my Battleship had a different kind of AI that randomly shoots with a plan! It too will give a good run for your money.
See Terry's Game Tutorial for copy, I assume source code is available.
b = b + ...
Reply
#8
(06-09-2023, 05:40 PM)bplus Wrote: Oh yeah my Battleship had a different kind of AI that randomly shoots with a plan! It too will give a good run for your money.
See Terry's Game Tutorial for copy, I assume source code is available.
Yep, all games on the tutorial site have source code included. Link to Battleship:

https://www.qb64tutorial.com/games#h.48r94ydobi6o
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply
#9
For all the power that has been put into games here, I seriously doubt that this has anything to do with actual AI.

@Donald Foster, first, to understand the basics of AI, that what AI actually means. For me, the best books for understanding AI are the two books by Hubert L. Dreyfus:
What Computers Can't Do: The Limits of Artificial Intelligence. 1972, ISBN 0-06-090613-8
What Computers Still Can't Do: A Critique of Artificial Reason. 1979, ISBN 0-262-54067-3

I have the volumes in German. You can only get them today, even in the English original, as antiquarian bookshops.

About Dreyfus (German)

Lisp & Prolog

Even if you have "only" read these two books, you know that with Basic you can at best create a kind of pseudo-AI, but not a real AI machine.

First came Lisp, then came Prolog, and then . . . what do one have today?

@Donald Foster Your game requires natural Intelligence!  Wink
Reply
#10
Here is Terry's Four-in-a-row game with a Minimax solver. I found this on an obscure website (I do not remember what it was now) and put it on GitHub for archiving.

QB64-Museum/FourinaRow at main · a740g/QB64-Museum · GitHub

I cleaned up the source just a bit to make it QB64-PE compatible and get the MIDI working.

The solver is kinda weak or is severely depth limited because I could beat it like 90% of the time. I'll look at it someday. Still, it is a work of art and a great resource to learn from.

@TerryRitchie you should probably look at it and maybe put it on www.qb64tutorial.com/games?
Reply




Users browsing this thread: 1 Guest(s)