Created
December 11, 2012 23:26
-
-
Save massimilianop7/4263307 to your computer and use it in GitHub Desktop.
pseudocodigo juego tres en raya
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a1 = [0,0,0] | |
var a2 = [0,0,0] | |
var a3 = [0,0,0] | |
var tablero = [a1,a2,a3] | |
tablero[0][1]; | |
function introPieza(jugador,x,y) | |
{ | |
si tablero[x][y] == 0 | |
tablero[x][y} == jugador | |
devuelve verdadero | |
si no | |
devuelve falso | |
} | |
function tresEnRaya() //Empezar juego, caracteristicas | |
{ | |
var jugador = 1 | |
var ganador = 0 | |
var ficha = falso | |
var fin = falso | |
var numeroFichas = 0 | |
mientras fin == falso o numeroFichas <9 | |
{ | |
mientras ficha == falso | |
//pedir pieza | |
var x = leer valor | |
var y = leer valor | |
//comprobar si la ficha es introducida | |
si introPieza(jugador,x,y) es verdadero | |
ficha = verdadero | |
si jugador = 1 | |
jugador = 2 | |
si no | |
jugador = 1 | |
numeroFichas ++ | |
si numeroFichas >= 5 | |
ganador = comprobarGanador | |
// != significa 'distinto de' | |
si ganador !=0 | |
fin = verdadero | |
} | |
} | |
function comprobarGanador () | |
{ | |
para var a = 0 mientras a<3 haz a++ //filas, columnas, diagonales | |
si tablero [a][0] == tablero [a][1] y tablero [a][1] == tablera [a][2] | |
devuelve tablero [a][0] | |
si tablero [0][a] == tablero [1][a] y tablero [1][a] == tablera [2][a] | |
devuelve tablero [0][a] | |
si tablero [0][0] == tablero [1][1] y tablero [1][1] == tablera [2][2] | |
devuelve tablero [0][0] | |
si tablero [0][2] == tablero [1][1] y tablero [1][1] == tablera [2][0] | |
devuelve tablero [0][2] | |
devuelve 0 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment