Java Tic Tac Toe

Discussion in 'Software' started by darkhorizon, Apr 24, 2005.

  1. darkhorizon

    darkhorizon Private First Class

    i wrote a homework assigment due in about 10 hours now, thats tic tac toe in java

    it almost works, i didnt program it in how to tell when there is a winner or not.

    if i have a grid like

    XXX
    00X
    X00

    for a tic tac toe board, each row in an array board[0], board[1], and board[2] respectively, is there an easy way to tell if there are 3 in a row?
     
  2. darkhorizon

    darkhorizon Private First Class

    nevermind, i just typed out every possibility
     
  3. iamien

    iamien Cptn "Eh!"

    I recently did this problem in c

    what is did was i have something like this

    Code:
    begin
    ' Board is an array nine elements holding player tokens
    ' Let us assume 0 = empty, 1 = player 1 has place a token
    ' 2 = player 2 has left a token
    ' Pseudo code
            Loop x = 1 to 3
                    counter = 0
                    token = board[x]
                    Loop y = x to (x+6) step 3
                           if  board[y] ==  token then
                                    couter++
                            end if
                    next
                    if counter = 3 then: winner = true and break
            next
    if winner = true then
            alert("The winner!")
    else
    ' I use a similar method for check the verticle rows
    ' then i ust checked both diagonals manualy
    ' good luck
    end
    
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds