The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
fer
Posted by: fer | February 10, 2011 @ 4:47pm
Java Code
[
Download
]
/* * awale.java 1.0 2011-01-31 * * Emulador del joc afric� awel�. * * Copyright 2011 Gerard Brull Blanes <gbblanes@gmail.com> * * This is free software, licensed under the GNU General Public License v3. * See http://www.gnu.org/licenses/gpl.html for more information. */ import library.inout.Terminal; import library.utilitats.Arr; public class awele { public static void main (String args[]) { int posIni,posFi; int[] taulell = {3,1,0,2,20,4,2,1,4,0,3,3}; int[] llavorsJugadors = {0,0}; int jugador = Terminal.readInt("Jugador ?"); mostraTaulell(taulell, llavorsJugadors); if (partidaAcabada(taulell)==true) { Terminal.print("\nPartida acabada"); if (quiGuanya(llavorsJugadors)==0) { Terminal.print("\nHi ha hagut un empat\n"); }else{ Terminal.print("\nHa guanyat el jugador %d\n", quiGuanya(llavorsJugadors)); } } //mostraTaulell(taulell, llavorsJugadors); posIni=demanaPosicio(taulell,jugador); posFi=mouLlavors(taulell,posIni); agafaLlavors(taulell,llavorsJugadors,jugador,posFi); } public static boolean filaBuida (int[] taulell, int indexInici, int indexFi) { boolean filaJugadorBuida=true; int i = 0; if ( indexInici >= 0 && indexFi <= 5 ) { for (i = 0; i <= 5; i++) { if ( taulell[i] != 0 ) { filaJugadorBuida=false; } } } else { for (i = 6; i <= 11; i++) { if ( taulell[i] != 0 ) { filaJugadorBuida=false; } } } return filaJugadorBuida; } public static boolean partidaAcabada (int[] taulell) { boolean partidaAcabada=false; if ( filaBuida(taulell, 0, 5 )|| filaBuida(taulell,6,11) ) { return partidaAcabada=true; }else{ return partidaAcabada=false; } } public static int quiGuanya (int[] llavorsJugadors) { int jugadorGuanyador; if ( llavorsJugadors[0] > llavorsJugadors[1] ) { jugadorGuanyador=1; }else if ( llavorsJugadors[0] < llavorsJugadors[1] ) { jugadorGuanyador=2; }else{ jugadorGuanyador=0; } return jugadorGuanyador; } public static void mostraTaulell (int[] taulell, int[] llavorsJugadors) { int i; Terminal.print("\n\n%19s%d llavors )\n", "Jugador 2 ( ",llavorsJugadors[1]); for (i = 11; i > 5; i--) { Terminal.print(" %d", taulell[i]); } Terminal.print("\n"); for (i = 0; i < 6 ; i++) { Terminal.print(" %d", taulell[i]); } Terminal.print("\n%19s%d llavors )\n\n\n", "Jugador 1 ( ",llavorsJugadors[0]); } public static int esbrinaPosicioTaulell (int posicio, int jugador) { int posIni; if (jugador==1) { return posIni=posicio-1; }else{ return posIni=5+posicio; } } public static int demanaPosicio (int[] taulell, int jugador) { int posicio, posIni; posicio = Terminal.readInt("Quina �s la posici� de les llavors que vols moure ? "); while (taulell[esbrinaPosicioTaulell(posicio,jugador)]==0) { posicio = Terminal.readInt("Quina �s la posici� de les llavors que vols moure ? "); } posIni=esbrinaPosicioTaulell(posicio,jugador); return posIni; } public static int mouLlavors(int[] taulell, int posIni) { int contador = taulell[posIni], posFi = posIni, nextPos; for (nextPos = posIni; contador > 0; contador--) { if (nextPos == Arr.size(taulell)-1) { taulell[0]++; nextPos = 0; posFi = 0; } else { taulell[nextPos + 1]++; nextPos++; } if (nextPos==posIni) { contador++; } posFi++; } taulell[posIni] = 0; Terminal.print("PosFi=%d", posFi); return posFi; } public static void agafaLlavors (int[] taulell, int[] llavorsJugadors, int jugador, int posFi) { int i, nextPos; if (jugador == 1) { if ( posFi > 6 ) { for (i=0; taulell[posFi-i]==1 || taulell[posFi+i] == 2 || taulell[posFi+i] == 3; i++) { llavorsJugadors[0]=llavorsJugadors[0]+taulell[posFi-i]; taulell[posFi-i]=0; } } }else{ for (i=0; (taulell[posFi-i]==1 || taulell[posFi-i] == 2 || taulell[posFi-i] == 3) && posFi-i < 6; i++) { //Terminal.print("posFi= %d - i = %d",posFi,i); llavorsJugadors[1]=llavorsJugadors[1]+taulell[posFi-i]; taulell[posFi-i]=0; } } mostraTaulell(taulell,llavorsJugadors); } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.55 / 8
55 Votes
http://codebin.yi.org/1103
page generated in 0.01 seconds