Guest User

Untitled

a guest
Oct 26th, 2021
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const claimSpace = function(section,pos) {
  2.     space = section[`${pos}`]
  3.     //console.log(space, ' was checked!')
  4.     if(space.owner === '') {
  5.         space.owner = myTeam;
  6.         if(myTeam === 'x') {
  7.             drawX(space.coords[0],space.coords[1],28,color_us)
  8.         } else {
  9.         primitiveFuncs.al_draw_circle(space.coords[0],space.coords[1],28,color_enemy,0)
  10.         }
  11.         drawFuncs.al_flip_display()
  12.         nextTeam = teams.indexOf(myTeam)+1
  13.         if(nextTeam < teams.length) {
  14.         myTeam = teams[nextTeam]
  15.         } else {
  16.         myTeam = teams[0]
  17.         }
  18.     // now we can do victory checks
  19.         if(turns >= (3*teams.length)-2) {
  20.             //console.log('we can win now')
  21.             letter = space.group
  22.             // ! Smart space checking is overrated, lets just brute force it
  23.             let tic = 0; // vertical score
  24.             let tac = 0; // horizontal score
  25.             let toe = 0; // diagonal score
  26.             let currentLetter
  27.             let currentRow
  28.             teamVictoryCheck = space.owner // Only need to check our team this turn, it's not really possible for your move to lead to their victory on YOUR turn
  29.             console.log(teamVictoryCheck)
  30.             for(let i = 0; i < 3; i++) {
  31.                 currentLetter = letters[i]
  32.                 currentRow = i+1;
  33.                 for(let i = 0; i < 3; i++) {
  34.                     // check row vertically
  35.                     if(ticTacToeBoard[`${letters[i]}`][`${currentRow}`].owner === teamVictoryCheck) {
  36.                     tic++
  37. //                  console.log('TIC!',tic, i, 'at ' + currentRow)
  38.                 } else {
  39.                     break;
  40.                 }
  41.             }
  42.                 if(tic === 3) {
  43.                     // Victory(myTeam)
  44.                 } else {
  45.                     tic = 0
  46.                 }
  47.                 for(let i = 1; i < 3; i++) {
  48.                     // check row horizontally
  49.                     if(ticTacToeBoard[`${currentLetter}`][`${i}`].owner === teamVictoryCheck) {
  50.                     tac++
  51. //                  console.log('TAC!',tac, i, 'at ' + currentLetter)
  52.                 } else {
  53.                     break;
  54.                     }
  55.                 }
  56.                 if(tac === 3) {
  57.                     // Victory(myTeam)
  58.                 }
  59.                 else {
  60.                     tac = 0
  61.                     }
  62.  
  63.                 }
  64.                 let a = {};
  65.                 if(
  66.                     (
  67.                         (a['x'] = Object.keys(ticTacToeBoard)) &&
  68.                         (a['y'] = ticTacToeBoard[`${a['x'][~~((a['x']).length / 2)]}`]) &&
  69.                         (a['z'] = Object.keys(a['y'])) &&
  70.                         (false)) ||
  71.                 a['y'][`${a['z'][~~(a['z'].length/2)]}`].owner === teamVictoryCheck
  72.                  ) {
  73.                 for(let i = 3; i > 0; i--) { // Right side diagonal
  74.                     let x = 3
  75.                     if(i < 3) {
  76.                         x = i+1
  77.                     }
  78.                     console.log(ticTacToeBoard[`${letters[i-1]}`][`${x}`])
  79.                     if(ticTacToeBoard[`${letters[i-1]}`][`${x}`].owner === teamVictoryCheck) {
  80.                         toe++
  81.                     } else {
  82.                         break;
  83.                     }
  84.                 }
  85.                 if(toe === 3) {
  86.                     // Victory(myTeam)
  87.                 } else {
  88.                 toe = 0
  89.                 }
  90.                 for(let i = 1; i < 4; i++) { // Left side diagonal
  91.                     if(ticTacToeBoard[`${letters[i-1]}`][`${i}`].owner === teamVictoryCheck) {
  92.                         toe++
  93.                     } else {
  94.                         break;
  95.                     }
  96.                 }
  97.                 if(toe === 3) {
  98.                     // Victory(myTeam)
  99.                 } else {
  100.                 toe = 0
  101.                 }
  102.             }
  103.         console.log('No victory yet! Awww')
  104.         tac = 0
  105.         tic = 0
  106.         toe = 0
  107.         } else {
  108.             console.log(turns,(3*teams.length)-1)
  109.             console.log('we can\'t win yet')
  110.         }
  111.         turns++
  112.     }
  113.     else {
  114.         console.log('We just tried to claim an already owned space!')
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment