Apagada docs

Aprendiendo a programar el pasado

Herramientas de usuario

Herramientas del sitio


en:basic:mini_mancala
Mini Mancala for Chipmunk Basic

by jose GMY (nepenthes)

Mancala is a bead game where each player takes a stack of coins from a circle of pits and redistributes the coins by putting a bead on each pit, from (selected pit+1) to (selected pit+ # of beads). Beads falling on two special pits at opposite sides are awarded to player. Player with most beads at own special pit wins.

This is a Chipmunk Basic program that plays a minified version of Mancala, called MiniMancala, that appeared in a issue of Scientific American.

10 rem MINI MANCALA
20 rem BASED ON CHRISTIAN FREELING "Glassbead and company" document.
30 dim pit(4)
40 for f = 1 to 4 : pit(f) = 2 : next f
50 input "Select starting player: Computer or Human (C/H)";r$
60 start = -1
70 if r$ = "C" or r$ = "c" then start = 1
80 if r$ = "H" or r$ = "h" then start = 0
90 if start = -1 then 50
100 print "Me:  [";pit(4);"] [";pit(3);"]"
110 print "You: [";pit(1);"] [";pit(2);"]"
120 if start = 0 then gosub 1000
130 if start = 1 then gosub 2000
135 winner = -1
140 if (pit(4) or pit(3)) = 0 then winner = 0
150 if (pit(1) or pit(2)) = 0 then winner = 1
160 start = (start+1) mod 2
170 if winner = -1 then 100
180 if winner = 1 then print "I "; :  else print "You ";
190 print "win"
999 end
1000 rem Human plays
1010 input "Take stones from which pit (1 or 2)";r
1020 b = pit(r)
1030 if b > 0 then 1050
1040 print "That pit is out of stones!" : goto 1010
1050 b = pit(r) : pit(r) = 0 : for f = 1 to b
1060 r = r+1 : if r > 4 then r = 1
1070 pit(r) = pit(r)+1
1080 next f
1090 return
2000 rem Computer plays
2010 rem Take from pit 4 or pit 3?
2020 rem Strategy:
2030 rem a) if a pit is empty, take from the other (it's compulsory).
2040 rem b) if pit3 has 1, take from pit3 to pit4
2050 rem c) if pit4 has 3
2060 if pit(3) = 0 then r = 4 : goto 1050
2070 if pit(4) = 0 then r = 3 : goto 1050
2080 if pit(3) = 1 then r = 3 : goto 1050
2090 rem PROBAR 2 MOVIMIENTOS
2100 dim ph(4) : dim score(4)
2110 for r1 = 3 to 4
2120 for f = 1 to 4 : ph(h) = pit(h) : next f
2130 r = r1
2140 gosub 2500
2150 for r2 = 1 to 2
2160 r = r2
2170 gosub 2500
2180 if ph(1) = 0 and ph(2) = 0 then score(r1) = score(r1)+1
2190 if ph(3) = 0 and ph(4) = 0 then score(r1) = score(r1)-2
2200 next r2 : next r1
2210 maxscore = -999
2220 for f = 3 to 4
2230 if score(f) > maxscore then r = f : maxscore = score(f)
2240 next f
2250 print "Computer has its move:"
2260 goto 1050
2500 b = ph(r) : ph(r) = 0 : for f = 1 to b
2510 r = r+1 : if r > 4 then r = 1
2520 ph(r) = ph(r)+1
2530 next f
2540 return
5000 dim p(4)
5010 for f = 1 to 4
5020 p(f) = 0
5030 next f
5040 n = 1
5050 p(n) = p(n)+1
5060 if p(n) > 8 then p(n) = 0 : n = n+1 : if n <= 4 then 5050
5070 if p(1)+p(2)+p(3)+p(4) = 8 then print p(1);p(2);p(3);p(4)
5080 if n <= 4 then 5040

Strategy Analysis (in Spanish)

Juego de los pozos
(cuatro pozos con reglas tipo mancala/kalah)

Jugadas ganadoras (gana el que las produce si juega las piezas de la izquierda)

1) Gana el que produce una combinación como
    XX/0n, donde n<3. Por tanto, son ganadoras las jugadas:
    
    XX/01=07/0116/01 25/01 34/01 43/01 52/01 61/01 70/01
    
    XX/02=08/0217/02 26/02 35/02 44/02 53/02 62/02 71/02 80/02 
 
0 4 /3 1:
    Los movimientos posibles son:
    
    a) 04/31>15/02>06/02>26/00 pierde.
    
    b) 04/31>14/30>05/30>16/01, entonces > 26/00 pierde.
Este sitio web utiliza cookies. Al utilizar el sitio web, usted acepta almacenar cookies en su computadora. También reconoce que ha leído y entendido nuestra Política de privacidad. Si no está de acuerdo abandone el sitio web.Más información
en/basic/mini_mancala.txt · Última modificación: 2013/01/09 13:56 por nepenthes