machine-learning,artificial-intelligence,tic-tac-toe,reinforcement-learning,q-learning
You have a Q value for each state-action pair. You update one Q value after every action you perform. More precisely, if applying action a1 from state s1 gets you into state s2 and brings you some reward r, then you update Q(s1, a1) as follows: Q(s1, a1) = Q(s1,...
c++,debugging,tic-tac-toe,alpha-beta-pruning
The problem is in your move function, as it returns a pointer to a local variable. When the function returns the local variables goes out of scope, and using pointers to those leads to undefined behavior.
java,clone,copy-constructor,tic-tac-toe
You have to physically copy your array yourself. You can do this with java.lang.System.arraycopy(): import java.util.Arrays; public class ArrayCopy { public static void main(String[] args) { // set up an empty source array char[][] src = new char[5][3]; // fill it with random digits for(int i = 0 ; i...
java,swing,for-loop,jbutton,tic-tac-toe
The win conditions for tic tac toe are: X - - - X - - - X X - - or - X - or - - X X - - - X - - - X private boolean colWinner() { for (int i = 0; i < 3; i++)...
java,ternary-operator,tic-tac-toe
return (value == 0 ? "X" : "O"); is the same as if(value == 0) return "X"; else return "O"; ...
As NUM_SQUARES == 9 and python is 0 indexed, the highest index you can access from the board is board[8] (which is the ninth place on the board). so take 1 away from all of the numbers in WAYS_TO_WIN and it should be fine. In more detail - the board...
java,recursion,tic-tac-toe,minimax
I have since looked over my code and realised I made a mistake while debugging. The working, edited code is below for anyone who is interested package tictactoe; import static tictactoe.Player.*; import java.util.Arrays; public class MinimaxTTT { private Player[] board = new Player[9]; private Player player = X; public MinimaxTTT()...
The w in lw/sw means word, which is a unit of 4 bytes on MIPS. The elements in your boardArray are bytes, not words. You've got a couple of alternatives: either make your array an array of words; or use lbu/sb instead of lw/ sw and skip the index scaling....
java,multidimensional-array,tic-tac-toe
You are not updating flag declared in your main method. Change each of checkForWinner(board); to flag = checkForWinner(board); Without this flag will never change and you will never leave your while (flag != true) (which could be simplified to while(!flag)) loop which means you will never execute displayWinner(player, flag) method....
c#,algorithm,artificial-intelligence,tic-tac-toe,montecarlo
Ok, I solved the problem by adding the code: //If this move is terminal and the opponent wins, this means we have //previously made a move where the opponent can always find a move to win.. not good if (game.GetWinner() == Opponent(startPlayer)) { current.parent.value = int.MinValue; return 0; } I...
c++,random,runtime,artificial-intelligence,tic-tac-toe
You need to remove the invalid moves from the equation, such as with the following pseudo-code, using an array to collect valid moves: possibleMoves = [] for each move in allMoves: if move is valid: add move to possibleMoves move = possibleMoves[random (possibleMoves.length)] That removes the possibility that you will...
I see two problems: The heuristic is wrong There is a problem with strcpy. The heuristic is wrong The Wikipedia pseudo-code says: if depth = 0 or node is a terminal node return the heuristic value of node Your implementation does this: if depth = 0 or node is a...
The key to understanding the two board functions you are having difficulty with, clearBoard and drawBoard, you need to understand the data structure that you're storing your game board in. This is, in fact, a pretty simple example. Your board is defined as an array of 9 items: int board[board_size];...
I think you must clone your board. In your's case you set '0' at all possible position MinimaxBoard child = new MinimaxBoard(board, position, 'O'); you must change to MinimaxBoard child = new MinimaxBoard(board.clone(), position, 'O'); and implement clone() method in your Board class Example of clone implementation: @Override public Object...
Your error is due to this line: if (entered >= 1 || entered <= 9) You need to use && instead of ||....
data Tile = EmptyTile | X | O deriving Eq tileWins :: Board -> Tile -> Bool tileWins b t = any (\row -> all (\col -> b!(row,col) == t) [1..3]) [1..3] || any (\col -> all (\row -> b!(row,col) == t) [1..3]) [1..3] || all (\rc -> b!(rc,rc) ==...
Your randomTicTacToeGame function runs a complete game of TicTacToe every time it is called. Your test code therefore runs 4 different games at each iteration If you want to run a single game per iteration, you should "save" the game result in a variable, and test that variable, as follows:...
java,multidimensional-array,tic-tac-toe
The problem is - board[i][2] != ' '. It should be board[i][2] != " " instead. ' ' is a char while board[i][2] is a String. Also, board[i][0] == board[i][1] is bug, do board[i][0].equals(board[i][1]) instead. And for the not-equals do !board[i][2].equals(" ")....
python,optimization,tic-tac-toe
You could hold a list of the indices for each row/column/diagonal. So for example, the first row should be sequence_indices = [(0, 0), (0, 1), (0, 2)]. The main diagonal should be sequence_indices = [(0, 0), (1, 1), (2, 2)]. Now whenever you write in your code vertcounter or diagcounter...
Two things to do (generally speaking): 1) change your main class - you are checking winner before first move and after last move... So game for should looks like this: for (i = 0; i < 9; i++) { if (KollaVinst(spelplan)) { break; } else { CheckMove(spelplan, rad, kolumn); }...
It's because the break statement only breaks out of the inner while loop. Try something like this: continuegame = True while continuegame == True: user_choice = int(raw_input('Choose a co-ordinate:')) if board[user_choice] != 'x' and board[user_choice] != 'o': board[user_choice] = user_side check_win() if check_win(): print 'You win!' break else: while True:...
You are recursively calling main(). The standard states : 3.6.1.3 "The function main shall not be used within a program." 5.2.2.9 "Recursive calls are permitted, except to the function named main" And you are reading the user input after this recursive call to main(), which, if this call ever succeed,...
Call checkForWinner after each turn. Once you get back true, you know that whoever was the last one to move is the winner. This is because you have checked the board before the last move, and there has been no winner at the time (otherwise, you would have exited the...
java,string,list,tic-tac-toe,brackets
For the list error you have to import java.util.* import java.util.* Importing LinkedList does not include using list....
you should use raw_input instead of input to get a string values in python 2.x
python,arrays,python-2.7,tic-tac-toe
I think what you need is to use a class. I could have tried to fix your code, but I think you need to re-think it completely. Logically, you could break it up into a game object that keeps track of the moves made for a single game. You can...
Managed to get the answer to this by using a little bit of help from my tutor and some liberal use of for (auto &child : childNodes) Node Code void Node::addToNodeList(int turn) { for (int i = 0; i < 3; i++) { for (int j = 0; j <...
It appears that you need to reamove scanf() from your code, scanf() blocks until input is given to the program, it returns the number of items that matched the format string if any, by the input. If you are generating the number with rand() then you don't need any input...
You can always check that the square element is empty, and if it is not, then don't perform any action: function display_input(square) { //We get the associated DOM element var element = document.getElementById(square); //If the element already contains something, then don't change it if(element.innerHTML != "") return; if(player_one == 1)...
Add checkfortie function as; function CheckforTie() { for(var i=1;i<10;i++) { if(getBox(i)=="") return false; } return true; } and update you switchTurn function to; function switchTurn() { if(checkForWinner(document.turn)) { setMessage("Congratulations " + document.turn + "! You Win!"); document.winner = document.turn; } else if(CheckforTie()) { setMessage("Its a TIE..!! Play again...!!!"); } else...
algorithm,artificial-intelligence,tic-tac-toe,heuristics
Wikipedia: tic-tac-toe says that there are only 362,880 possible tic-tac-toe games. A brute force approach to proving your algorithm would be to exhaustively search the game tree, having your opponent try each possible move at each turn, and see if your algorithm ever loses (it's guaranteed a win or draw...
java,if-statement,multidimensional-array,tic-tac-toe
Your if statement looks to be syntactically incorrect: if(m[0][i] == [1][i] && m[1][i] == m[2][i]){ The [1][i] is missing an m before it. It should be this: if(m[0][i] == m[1][i] && m[1][i] == m[2][i]){ The same applies to the other if statement: Change if(m[0][0] == [1][1] && m[1][1] == m[2][2]){...
MinMax is very dependent on having a good evaluation function (the function that "scores" a board, to tell you how good it is). Your evaluation function should be as follows: If the game is won, lots of points for the winner. Nothing matters after the game is won. Otherwise, give...
Algorithm 2 would be the way to go, and frankly probably a lot easier than 1 to code anyway. The naive version would check exactly the 12 conditions you state. An even faster version could check one adjacent first and not even bother checking the 2-away spots if it doesn't...
I would suggest using a switch case in the last do while loop (see example) I think you simply need to check if the field you are referencing is already taken! ** The check()** void check (char *c, int *move){ if(*c == '0'){ *c = '1'; }else { printf("\nThis...
jquery,html,css,hover,tic-tac-toe
To fix this, you just make the blue and yellow classes a little more specific. Instead of: .yellow { background-color: #ffc300; } .blue { background-color: #73d2c9; } ...try something like this: td.box_cell.yellow { background-color: #ffc300; } td.box_cell.blue { background-color: #73d2c9; } Here's a simplified version of your code to demonstrate...
I you convert your if statements to combined if else if statements than what is left in your else case will be the tie. if(winRow1('O' , ttt)) System.out.println("Your game " + gameNum + ": O won the game by row 1"); else if(winRow2('O' , ttt)) System.out.println("Your game " + gameNum...
javascript,html,if-statement,tic-tac-toe
On every call of display_input, you intialise a new player_one variable with the same value: 1. Move the declaration outside of the function, so that subsequent calls will actually toggle the (one) higher-scoped variable: var player_one = 1; function display_input(square){ if ( player_one == 1 ){ document.getElementById(square).innerHTML = "X"; player_one...
c++,arrays,function,tic-tac-toe
#include <iostream> using namespace std; char turn = 'X'; bool draw = false; bool gameover = false; char board[3][3] = { { '1', '2', '3' }, { '4', '5', '6' }, { '7', '8', '9' } }; int main() { while (!gameover) { cout << "\nPlayer 1 [X] --- Player...