Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const claimSpace = function(section,pos) {
- space = section[`${pos}`]
- //console.log(space, ' was checked!')
- if(space.owner === '') {
- space.owner = myTeam;
- if(myTeam === 'x') {
- drawX(space.coords[0],space.coords[1],28,color_us)
- } else {
- primitiveFuncs.al_draw_circle(space.coords[0],space.coords[1],28,color_enemy,0)
- }
- drawFuncs.al_flip_display()
- nextTeam = teams.indexOf(myTeam)+1
- if(nextTeam < teams.length) {
- myTeam = teams[nextTeam]
- } else {
- myTeam = teams[0]
- }
- // now we can do victory checks
- if(turns >= (3*teams.length)-2) {
- //console.log('we can win now')
- letter = space.group
- // ! Smart space checking is overrated, lets just brute force it
- let tic = 0; // vertical score
- let tac = 0; // horizontal score
- let toe = 0; // diagonal score
- let currentLetter
- let currentRow
- 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
- console.log(teamVictoryCheck)
- for(let i = 0; i < 3; i++) {
- currentLetter = letters[i]
- currentRow = i+1;
- for(let i = 0; i < 3; i++) {
- // check row vertically
- if(ticTacToeBoard[`${letters[i]}`][`${currentRow}`].owner === teamVictoryCheck) {
- tic++
- // console.log('TIC!',tic, i, 'at ' + currentRow)
- } else {
- break;
- }
- }
- if(tic === 3) {
- // Victory(myTeam)
- } else {
- tic = 0
- }
- for(let i = 1; i < 3; i++) {
- // check row horizontally
- if(ticTacToeBoard[`${currentLetter}`][`${i}`].owner === teamVictoryCheck) {
- tac++
- // console.log('TAC!',tac, i, 'at ' + currentLetter)
- } else {
- break;
- }
- }
- if(tac === 3) {
- // Victory(myTeam)
- }
- else {
- tac = 0
- }
- }
- let a = {};
- if(
- (
- (a['x'] = Object.keys(ticTacToeBoard)) &&
- (a['y'] = ticTacToeBoard[`${a['x'][~~((a['x']).length / 2)]}`]) &&
- (a['z'] = Object.keys(a['y'])) &&
- (false)) ||
- a['y'][`${a['z'][~~(a['z'].length/2)]}`].owner === teamVictoryCheck
- ) {
- for(let i = 3; i > 0; i--) { // Right side diagonal
- let x = 3
- if(i < 3) {
- x = i+1
- }
- console.log(ticTacToeBoard[`${letters[i-1]}`][`${x}`])
- if(ticTacToeBoard[`${letters[i-1]}`][`${x}`].owner === teamVictoryCheck) {
- toe++
- } else {
- break;
- }
- }
- if(toe === 3) {
- // Victory(myTeam)
- } else {
- toe = 0
- }
- for(let i = 1; i < 4; i++) { // Left side diagonal
- if(ticTacToeBoard[`${letters[i-1]}`][`${i}`].owner === teamVictoryCheck) {
- toe++
- } else {
- break;
- }
- }
- if(toe === 3) {
- // Victory(myTeam)
- } else {
- toe = 0
- }
- }
- console.log('No victory yet! Awww')
- tac = 0
- tic = 0
- toe = 0
- } else {
- console.log(turns,(3*teams.length)-1)
- console.log('we can\'t win yet')
- }
- turns++
- }
- else {
- console.log('We just tried to claim an already owned space!')
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment