Search Results

Search found 3 results on 1 pages for 'gomoku'.

Page 1/1 | 1 

  • How do i start with Gomoku?

    - by firstTry
    I read about Gomoku that it can be implemented using Minimax and Alpha-Beta Pruning algorithms. So, i read these algorithms and now understand how the game will be solved. But when i sat to down to code, I am facing problem how to approach it. As in , How to design the prototype functions like getNextMove or Max(Move) ? How will the next move searched? Till when should i apply the minimax algorithm. I know i can find the code online, but i want to do it myself. Can anyone please point me in the right direction?

    Read the article

  • Gomoku array-based AI-algorithm?

    - by Lasse V. Karlsen
    Way way back (think 20+ years) I encountered a Gomoku game source code in a magazine that I typed in for my computer and had a lot of fun with. The game was difficult to win against, but the core algorithm for the computer AI was really simply and didn't account for a lot of code. I wonder if anyone knows this algorithm and has some links to some source or theory about it. The things I remember was that it basically allocated an array that covered the entire board. Then, whenever I, or it, placed a piece, it would add a number of weights to all locations on the board that the piece would possibly impact. For instance (note that the weights are definitely wrong as I don't remember those): 1 1 1 2 2 2 3 3 3 444 1234X4321 3 3 3 2 2 2 1 1 1 Then it simply scanned the array for an open location with the lowest or highest value. Things I'm fuzzy on: Perhaps it had two arrays, one for me and one for itself and there was a min/max weighting? There might've been more to the algorithm, but at its core it was basically an array and weighted numbers Does this ring a bell with anyone at all? Anyone got anything that would help?

    Read the article

  • PHP session not working with JQuery Ajax?

    - by Bolt_Head
    Update, Solved: After all this I found out that I was calling an old version of my code in the update ajax. 'boardControl.php' instead of 'boardUpdate.php' These are the kinds of mistakes that make programing fun. I'm writing a browser gomoku game. I have the ajax statement that allows the player to play a piece. $(document).ready(function() { $("td").live('click',function(){ var value = $(this).attr('id'); $.get('includes/boardControl.php',{play: value, bid: bid}); }); }); value = board square location bid = board ID Before creating a user login for player identification, the server side php had a temporary solution. It would rotate the piece state for the squares when clicked instead of knowing what player to create them for. After creating login stuff I set a session variable for the player's ID. I was hoping to read the session ID from the php during the ajax request and figure out what player they are from there. session_start(); ... $playerId = $_SESSION['char']; $Query=("SELECT p1, p2 FROM board WHERE bid=$bid"); $Result=mysql_query($Query); $p1 = mysql_result($Result,0,"p1"); $p2 = mysql_result($Result,0,"p2"); $newPiece = 0; //*default no player if($playerId == $p1) $newPiece = 1; if($playerId == $p2) $newPiece = 2; For some reason when I run the full web app, the pieces still cycle though, even after I deleted the code to make them cycle. Furthermore, after logging in If i manually load the php page in the browser, it modifies the database correctly (where it only plays pieces belonging to that player) and outputs the correct results. It seems to me that the session is not being carried over when used with Ajax. Yet Google searches tell me that, sessions do work with Ajax. Update: I'm trying to provide more information. Logging in works correctly. My ID is recognized and I printed it out next to the board to ensure that I was retrieving it correctly. The ajax request does update the board. The values passed are correct and confirmed with firebug's console. However instead of placing pieces only for the player they belong to it cycles though the piece states (0,1,2). When manually browsing to boardUpdate.php and putting in the same values sent from the Ajax the results seen in the echo'ed response indicates that the corresponding piece is played each time as intended. Same results on my laptop after fresh load of firefox. Manually browsing to boardUpdate.php without logging in before hand leave the board unchanged (as intended when no user is found in the session). I've double checked the that session_start() is on the php files and double checked the session ID variables. Hope this extra information helps, i'm running out of ideas what to tell you. Should I load up the full code? Update 2: After checking the Ajax responce in fire-bug I realized that the 'play' request does not get a result, and the board is not updated till the next 'update'. I'm still looking into this but I'll post it here for you guys too. boardUpdate.php Notable places are: Refresh Board(line6) Place Piece(line20) function boardUpdate($turnCount) (line63) <?php session_start(); require '../../omok/dbConnect.php'; //*** Refresh Board *** if(isset($_GET['update'])) { $bid = $_GET['bid']; $Query=("SELECT turn FROM board WHERE bid=$bid"); $Result=mysql_query($Query); $turnCount=mysql_result($Result,0,"turn"); if($_GET['turnCount'] < $turnCount) //** Turn increased { boardUpdate($turnCount); } } //*** Place Piece *** if(isset($_GET['play'])) // turn order? player detect? { $squareID = $_GET['play']; $bid = $_GET['bid']; $Query=("SELECT turn, boardstate FROM board WHERE bid=$bid"); $Result=mysql_query($Query); $turnCount=mysql_result($Result,0,"turn"); $boardState=mysql_result($Result,0,"boardstate"); $turnCount++; $playerId = $_SESSION['char']; $Query=("SELECT p1, p2 FROM board WHERE bid=$bid"); $Result=mysql_query($Query); $p1 = mysql_result($Result,0,"p1"); $p2 = mysql_result($Result,0,"p2"); $newPiece = 0; //*default no player if($playerId == $p1) $newPiece = 1; if($playerId == $p2) $newPiece = 2; // if($newPiece != 0) // { $oldPiece = getBoardSpot($squareID, $bid); $oldLetter = $boardState{floor($squareID/3)}; $slot = $squareID%3; //***function updateCode($old, $new, $current, $slot)*** $newLetter = updateCode($oldPiece, $newPiece, $oldLetter, $slot); $newLetter = value2Letter($newLetter); $newBoard = substr_replace($boardState, $newLetter, floor($squareID/3), 1); //** Update Query for boardstate & turn $Query=("UPDATE board SET boardState = '$newBoard', turn = '$turnCount' WHERE bid = '$bid'"); mysql_query($Query); // } boardUpdate($turnCount); } function boardUpdate($turnCount) { $json = '{"turnCount":"'.$turnCount.'",'; //** turnCount ** $bid = $_GET['bid']; $Query=("SELECT boardstate FROM board WHERE bid='$bid'"); $Result=mysql_query($Query); $Board=mysql_result($Result,0,"boardstate"); $json.= '"boardState":"'.$Board.'"'; //** boardState ** $json.= '}'; echo $json; } function letter2Value($input) { if(ord($input) >= 48 && ord($input) <= 57) return ord($input) - 48; else return ord($input) - 87; } function value2Letter($input) { if($input >= 10) return chr($input += 87); else return chr($input += 48); } //*** UPDATE CODE *** updates an letter with a new peice change and returns result letter. //***** $old : peice value before update //***** $new : peice value after update //***** $current : letterValue of code before update. //***** $slot : which of the 3 sqaures the change needs to take place in. function updateCode($old, $new, $current, $slot) { if($slot == 0) {// echo $current,"+((",$new,"-",$old,")*9)"; return letter2Value($current)+(($new-$old)*9); } else if($slot == 1) {// echo $current,"+((",$new,"-",$old,")*3)"; return letter2Value($current)+(($new-$old)*3); } else //slot == 2 {// echo $current,"+((",$new,"-",$old,")"; return letter2Value($current)+($new-$old); } }//updateCode() //**** GETBOARDSPOT *** Returns the peice value at defined location on the board. //****** 0 is first sqaure increment +1 in reading order (0-254). function getBoardSpot($squareID, $bid) { $Query=("SELECT boardstate FROM board WHERE bid='$bid'"); $Result=mysql_query($Query); $Board=mysql_result($Result,0,"boardstate"); if($squareID %3 == 2) //**3rd spot** { if( letter2Value($Board{floor($squareID/3)} ) % 3 == 0) return 0; else if( letter2Value($Board{floor($squareID/3)} ) % 3 == 1) return 1; else return 2; } else if($squareID %3 == 0) //**1st spot** { if(letter2Value($Board{floor($squareID/3)} ) <= 8) return 0; else if(letter2Value($Board{floor($squareID/3)} ) >= 18) return 2; else return 1; } else //**2nd spot** { return floor(letter2Value($Board{floor($squareID/3)}))/3%3; } }//end getBoardSpot() ?> Please help, I'd be glad to provide more information if needed. Thanks in advance =)

    Read the article

1