"================================================================
_____________________________________________
|   Trevin S  ||   Spring    ||    2022     |
|_____________||_____________||_____________|
|     Tic     ||     Tac     ||     Toe     |
|_____________||_____________||_____________|
|   Bologna   || Programming ||  Language   |
|_____________||_____________||_____________|

TODO:
================================================================
- Fix tie case
- Condense code by adding player counter
- Check to make sure input is a valid number

================================================================"

"Note; Leave 0 Empty! This is the default memory block we use to print."

"Initialize Index memory 1_9 to ' ' (Space)
To hold the vals of (X | O) cells in the game"

>{ :10 + :#10 +#10 +48 }9

"Initialize Index 10 to \n (linebreak)"
:10 _ +10 .

"Initialize Index 11 to ' ' (Space)"
:11 +32

"Initialize Index 12 to '|'"
:12 +124

"Initialize Index 13 to 'X'"
:13 +88

"Initialize Index 14 to 'O'"
:14 +79

:0

"Print the gameboard
================================================================"

Print a row of hyphens
_ +45 .7 _ #10.


Print top row | mem|1| | mem|2| | mem|3| |
_ #12. #1. #12. #2. #12. #3. #12. #10.


Print a row of hyphens
_ +45 .7 _ #10.


Print middle row | mem|4| | mem|5| | mem|6| |
_ #12. #4. #12. #5. #12. #6. #12. #10.


Print a row of hyphens
_ +45 .7 _ #10.


Print bottom row | mem|7| | mem|8| | mem|9| |
_ #12. #7. #12. #8. #12. #9. #12. #10.


Print a row of hyphens
_ +45 .7 _ #10.

"End Gameboard Print
================================================================"

"Start Game Loop
================================================================"
{

  "Player 1 Input
  ================================================================"

  #10.

  "Print: Player 1 - "

  _ +80. _ +108. _ +97. _ +121. _ +101. _ +114. _ +32. _ +49. _ +32. _ +45. _ #11.

  "Print: Pick a cell 1 - 9) "

  +80. _ +105. _ +99. _ +107. _ +32. _ +97. _ +32. _ +67. _ +101. _ +108. _ +108. _ +32. _ +49. _ +32. _ +45. _ +32. _ +57. _ +41. _ #11.

  "Set index 100 to 1, allowing the while loop to continue until valid entry of player"
  :100 _ +1

  [

  "Character input"
  :50 _ , :0

  #10.

  "Go to the index of the selected cell"
  :#50

  "If the selected cell was written to, ask for another input"
  ?(#>78){
    :0
    _ +84._ +104._ +97._ +116._ +32._ +99._ +101._ +108._ +108._ +32._ +105._ +115._ +32._ +97._ +108._ +114._ +101._ +97._ +100._ +121._ +32._ +116._ +97._ +107._ +101._ +110._ +33._ +32._ +80._ +108._ +101._ +97._ +115._ +101._ +32._ +99._ +104._ +111._ +111._ +115._ +101._ +32._ +97._ +110._ +32._ +101._ +109._ +112._ +116._ +121._ +32._ +111._ +110._ +101._ +46._

    #10.

    "Print: Player 1 -"
  _ +80. _ +108. _ +97. _ +121. _ +101. _ +114. _ +32. _ +49. _ +32. _ +45. _ #11.

    "Print: Pick a cell 1-9)"
    +80. _ +105. _ +99. _ +107. _ +32. _ +97. _ +32. _ +67. _ +101. _ +108. _ +108. _ +32. _ +49. _ +32. _ +45. _ +32. _ +57. _ +41. _ #11.

   }

  :#50

  "Ensure that the selected cell is not already occupied, and put an X in it"
  ?(#<#14){ :100 _ :#50 _ +#13 :0 }

  :100

  ]

  "End Player 1 Input
  ================================================================"


  "Print the gameboard
  ================================================================"

  "Print a row of hyphens"
  _ +45 .7 _ #10.


  "Print top row | mem|1| | mem|2| | mem|3| |"
  _ #12. #1. #12. #2. #12. #3. #12. #10.


  "Print a row of hyphens"
  _ +45 .7 _ #10.


  "Print middle row | mem|4| | mem|5| | mem|6| |"
  _ #12. #4. #12. #5. #12. #6. #12. #10.


  "Print a row of hyphens"
  _ +45 .7 _ #10.


  "Print bottom row | mem|7| | mem|8| | mem|9| |"
  _ #12. #7. #12. #8. #12. #9. #12. #10.


  "Print a row of hyphens"
  _ +45 .7 _ #10.

  "End Gameboard Print
  ================================================================"

  "Checking for player 1 game win
  ================================================================"

  :0 _

  "If a row contains 3 of a kind"
  ?(#1=#2){ ?(#2=#3){ ?(#1>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+49._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  ?(#4=#5){ ?(#5=#6){ ?(#4>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+49._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  ?(#7=#8){ ?(#8=#9){ ?(#7>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+49._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  "If a column contains 3 of a kind"
  ?(#1=#4){ ?(#4=#7){ ?(#1>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+49._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  ?(#2=#5){ ?(#5=#8){ ?(#2>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#2=#13){+49._} ?(#2=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  ?(#3=#6){ ?(#6=#9){ ?(#3>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#3=#13){+49._} ?(#3=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  "If a diagnol contains 3 of a kind"
  ?(#1=#5){ ?(#5=#9){ ?(#1>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+49._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  ?(#3=#5){ ?(#5=#7){ ?(#3>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#3=#13){+49._} ?(#3=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  "================================================================"


  "Player 2 Input
  ================================================================"

  #10.

  "Print: Player 2 - "

  _ +80. _ +108. _ +97. _ +121. _ +101. _ +114. _ +32. _ +50. _ +32. _ +45. _ #11.

  "Print: Pick a cell 1 - 9) "

  +80. _ +105. _ +99. _ +107. _ +32. _ +97. _ +32. _ +67. _ +101. _ +108. _ +108. _ +32. _ +49. _ +32. _ +45. _ +32. _ +57. _ +41. _ #11.

  "Set index 100 to 1, allowing the while loop to continue until valid entry of player"
  :100 _ +1

  [

  "Character input"
  :50 _ , :0

  #10.

  "Go to the index of the selected cell"
  :#50

  "If the selected cell was written to, ask for another input"
  ?(#>78){
    :0
    _ +84._ +104._ +97._ +116._ +32._ +99._ +101._ +108._ +108._ +32._ +105._ +115._ +32._ +97._ +108._ +114._ +101._ +97._ +100._ +121._ +32._ +116._ +97._ +107._ +101._ +110._ +33._ +32._ +80._ +108._ +101._ +97._ +115._ +101._ +32._ +99._ +104._ +111._ +111._ +115._ +101._ +32._ +97._ +110._ +32._ +101._ +109._ +112._ +116._ +121._ +32._ +111._ +110._ +101._ +46._

    #10.

    "Print: Player 2 -"
  _ +80. _ +108. _ +97. _ +121. _ +101. _ +114. _ +32. _ +50. _ +32. _ +45. _ #11.

    "Print: Pick a cell 1-9)"
    +80. _ +105. _ +99. _ +107. _ +32. _ +97. _ +32. _ +67. _ +101. _ +108. _ +108. _ +32. _ +49. _ +32. _ +45. _ +32. _ +57. _ +41. _ #11.

  }

  :#50

  "Ensure that the selected cell is not already occupied, and put a O in it"
  ?(#<#14){ :100 _ :#50 _ +#14 :0 }

  :100

  ]

  "End Player 2 Input
  ================================================================"

  "Print the gameboard
  ================================================================"

  "Print a row of hyphens"
  _ +45 .7 _ #10.


  "Print top row | mem|1| | mem|2| | mem|3| |"
  _ #12. #1. #12. #2. #12. #3. #12. #10.


  "Print a row of hyphens"
  _ +45 .7 _ #10.


  "Print middle row | mem|4| | mem|5| | mem|6| |"
  _ #12. #4. #12. #5. #12. #6. #12. #10.


  "Print a row of hyphens"
  _ +45 .7 _ #10.


  "Print bottom row | mem|7| | mem|8| | mem|9| |"
  _ #12. #7. #12. #8. #12. #9. #12. #10.


  "Print a row of hyphens"
  _ +45 .7 _ #10.

  "End Gameboard Print
  ================================================================"

  "Checking for player 2 game win
  ================================================================"

  :0 _

  "If a row contains 3 of a kind"
  ?(#1=#2){ ?(#2=#3){ ?(#1>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+50._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  ?(#4=#5){ ?(#5=#6){ ?(#4>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+50._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  ?(#7=#8){ ?(#8=#9){ ?(#7>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+50._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  "If a column contains 3 of a kind"
  ?(#1=#4){ ?(#4=#7){ ?(#1>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+50._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  ?(#2=#5){ ?(#5=#8){ ?(#2>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#2=#13){+50._} ?(#2=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  ?(#3=#6){ ?(#6=#9){ ?(#3>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#3=#13){+50._} ?(#3=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  "If a diagnol contains 3 of a kind"
  ?(#1=#5){ ?(#5=#9){ ?(#1>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+50._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  ?(#3=#5){ ?(#5=#7){ ?(#3>78){
    +71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#3=#13){+50._} ?(#3=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
  } } }

  "================================================================"


"End Game Loop
================================================================"
}5
