Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- board = ['-','-','-';'-','-','-';'-','-','-'];
- running = 1;
- round = 0;
- fprintf('Welcome to tictacto bitches!\n');
- while(running == 1)
- %figure whos turn it is
- if(mod(round,2) == 0)
- fprintf('\n~= Xs Turn =~\n');
- turn = 'X';
- else
- fprintf('\n~= Os Turn =~\n');
- turn = 'O';
- end
- col = input('Column:');
- row = input('Row: ');
- % check if space if valid, if so then set according to turn
- if (isempty(col) || isempty(row))
- fprintf('\n!> Enter a number dumbass\n');
- else
- if (col >= 0 && col <= 3 && row >= 0 && row <= 3)
- if(board(row,col) == '-')
- round = round + 1;
- board(row,col) = turn;
- else
- fprintf('\n That space is taken jerkoff\n');
- end
- else
- fprintf('\n This is tictactoe idiot, try a space that exists\n');
- end
- end
- fprintf('\n');
- disp(board);
- fprintf('\n');
- % VICTORY CONDITIONS
- % row 1
- if(board(1,1) == board(1,2) && board(1,2) == board(1,3))
- if (board(1,1) ~= '-')
- winner = board(1,1);
- fprintf('%s wins... congratualtions on beating yourself without porn\n', winner);
- running = 0;
- end
- end
- % row 2
- if(board(2,1) == board(2,2) && board(2,2) == board(2,3))
- if (board(2,1) ~= '-')
- winner = board(2,1);
- fprintf('%s wins... congratualtions on beating yourself without porn\n', winner);
- running = 0;
- end
- end
- % row 3
- if(board(3,1) == board(3,2) && board(3,2) == board(3,3))
- if(board(3,1) ~= '-')
- winner = board(3,1);
- fprintf('%s wins... congratualtions on beating yourself without porn\n', winner);
- running = 0;
- end
- end
- % column 1
- if(board(1,1) == board(2,1) && board(2,1) == board(3,1))
- if (board(1,1) ~= '-')
- winner = board(1,1);
- fprintf('%s wins... congratualtions on beating yourself without porn\n', winner);
- running = 0;
- end
- end
- % column 2
- if(board(1,2) == board(2,2) && board(2,2) == board(3,2))
- if (board(1,2) ~= '-')
- winner = board(1,2);
- fprintf('%s wins... congratualtions on beating yourself without porn\n', winner);
- running = 0;
- end
- end
- % column 3
- if(board(1,3) == board(2,3) && board(2,3) == board(3,3))
- if (board(1,3) ~= '-')
- winner = board(1,3);
- fprintf('%s wins... congratualtions on beating yourself without porn\n', winner);
- running = 0;
- end
- end
- % backward cross
- if(board(1,1) == board(2,2) && board(2,2) == board(3,3))
- if (board(1,1) ~= '-')
- winner = board(1,1);
- fprintf('%s wins... congratualtions on beating yourself without porn\n', winner);
- running = 0;
- end
- end
- % foward cross
- if(board(3,1) == board(2,2) && board(2,2) == board(1,3))
- if (board(3,1) ~= '-')
- winner = board(3,1);
- fprintf('%s wins... congratualtions on beating yourself without porn\n', winner);
- running = 0;
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement