debug version of power, the last version is available here
# Modules from kandinsky import fill_rect as rect,set_pixel as set,draw_string as ds from ion import keydown as k from time import sleep # Choose number of players def menu(nbPlayers=0,first=1): rect(0,0,320,222,SKY) ds("POWER !",125,20,(255,0,0),SKY) ds("Nombre de joueurs:",70,50,(0,0,255),SKY) ds("+",155,90,TXT,SKY) ds("-",155,150,TXT,SKY) while k(4):1 while not k(4): if k(1) or k(2) or first: nbPlayers,first=(nbPlayers+(k(1)-k(2)))%3,0 ds(str(nbPlayers+2),155,120,TXT,SKY) while k(1) or k(2):1 return nbPlayers+2 # Dram the cell in x,y def draw_cell(x,y,case=0,first=0): if first: rect(3+x*24,3+y*24,23,23,COLORS[int(FIELD[y*9+x])]) for i in range(nbPlayers): for l in range(9):# Units if l in FIELDS[y][x][i]: rect(x*24+8,y*24+8,13,13,TXT) rect(x*24+10,y*24+10,9,9,COLORS[i+3]) break if 9 in FIELDS[y][x][i]:# Flag for j in range(15): for k in range(15): if FLAG[j*15+k]=="1":set(8+x*24+k,9+y*24+j,TXT) elif FLAG[j*15+k]=="2":set(8+x*24+k,9+y*24+j,COLORS[i+3]) if case>0: if case==1:c=(255,0,255) elif case==2:c=(COLORS[int(FIELD[y*9+x])]) rect(3+x*24,3+y*24,23,2,c) rect(3+x*24,3+y*24,2,23,c) rect(26+x*24,26+y*24,-23,-2,c) rect(26+x*24,26+y*24,-2,-23,c) def draw_arrow(x,y,c): for i in range(7): for j in range(15): if ARROW[i*15+j]=="1":set(x+j,y+i,c) # Variables SKY,TXT=(255,255,255),(0,0,0) COLORS=[(0,0,0),(0,0,255),(255,255,100),(255,0,0),(0,255,0),(0,255,255),(255,255,0)] FIELD="211121112133315551133315551133315551211121112166614441166614441166614441211121112" FLAG="001110000000000001122100000000001122221100000001122222211000001122222222100001122222211000001122221100000001122110000000001111000000000001100000000000001100000000000001100000000000111111000000000111111000000000000000000000000" ARROW="000000110000000000011110000000001111111111111111111111111111001111111111111000011110000000000000110000000" TYPES=["Sea","Island","P1","P2","P3","P4"] UNITS=[["Soldat",1,1,2],["Avion",3,3,3],["tank",2,4,5],["bateau",2,10,10],["regiment",2,10,20],["chasseur",5,30,30],["char",4,40,40],["cuirasse",3,50,50],["Missile",0,100],["drapeau"]] ACTIONS=["MOVE","GENERATE","FUSE"] BASES=[[0,0],[8,8],[0,8],[8,0]] X,Y=4,4 nbPlayers=menu() FIELDS=[[[[]for i in range(nbPlayers)]for X in range(9)]for Y in range(9)] POWER=[0 for i in range(nbPlayers)] #tour=nbPlayers-1 tour=0 # Configure flags FIELDS[0][0][0].append(9) FIELDS[8][8][1].append(9) if nbPlayers>2:FIELDS[0][8][2].append(9) if nbPlayers>3:FIELDS[8][0][3].append(9) # Tests FIELDS[7][8][0].append(0) FIELDS[3][5][1].append(5) FIELDS[3][5][1].append(5) FIELDS[3][5][1].append(5) for i in range(9):FIELDS[4][4][1].append(i) # NEW ROUND LOOP while 1: tour,earn,earned,move=(tour+1)%nbPlayers,0,0,-1 # NEW SCREEN LOOP while 1: rect(0,0,320,222,SKY) rect(0,0,222,222,TXT) for y in range(9): for x in range(9): draw_cell(x,y,0,1) if int(FIELD[y*9+x])>2 and int(FIELD[y*9+x])!=tour+3 and earn==0: POWER[tour]+=len(FIELDS[y][x][tour]) earned+=1 ds("Round: ",230,0,TXT,SKY) ds("P"+str(tour+1),300,0,TXT,COLORS[tour+3]) ds("POWER: "+str(POWER[tour]),240,40,TXT,(255,255,0)) first,earn,brek,brak=1,1,0,0 while k(4):1 # ROUND LOOP while 1: # Validation bloc if k(52): choice,second=0,1 rect(100,71,120,70,TXT) rect(103,74,114,64,SKY) ds("Valider?",120,81,TXT,SKY) ds("Oui",115,111,(0,255,0),SKY) ds("Non",175,111,(255,0,0),SKY) while not k(4): if k(0) or k(3) or second: rect(105+choice*60,111,10,18,SKY) rect(145+choice*60,111,10,18,SKY) choice,second=(choice+k(3)-k(0))%2,0 ds("[",105+choice*60,111,TXT,SKY) ds("]",145+choice*60,111,TXT,SKY) while k(0) or k(3):1 if choice==0:brek=1 break # Selection bloc if k(0) or k(1) or k(2) or k(3) or first: first=0 if move>-1: ds("Select a",225,100,(0,0,255),SKY) ds("cell:",225,120,(0,0,255),SKY) if max(X+(k(3)-k(0)),cell[0])-min(X,cell[0])<=UNITS[units_cell[move]][1] and max(Y,cell[1])-min(Y,cell[1])<=UNITS[units_cell[move]][1]: draw_cell(X,Y,2) X,Y=(X+(k(3)-k(0)))%9,(Y+(k(2)-k(1)))%9 draw_cell(X,Y,1) else: draw_cell(X,Y,2) X,Y=(X+(k(3)-k(0)))%9,(Y+(k(2)-k(1)))%9 draw_cell(X,Y,1) ds("→ "+TYPES[int(FIELD[Y*9+X])-1]+" ",222,182,TXT,SKY) ds("["+str(X)+";"+str(Y)+"]",246,202,(255,0,0),SKY) while k(0) or k(1) or k(2) or k(3):1 # Action bloc if k(4) and len(FIELDS[Y][X][tour])>0 and move==-1: units,second,action,actions,units_cell,cell=-1,1,0,[],[],[X,Y] rect(10,10,300,202,TXT) rect(13,13,294,196,SKY) ds("CELL:",15,15,TXT,SKY) ds("["+str(X)+" "+str(Y)+"]",70,15,(255,0,0),SKY) ds("ACTIONS:",180,50,(255,0,0),SKY) if 9 in FIELDS[Y][X][tour]:ds("YOUR FLAG",210,15,TXT,COLORS[3+tour]) for i in range(9): if i in FIELDS[Y][X][tour]: units+=1 units_cell.append(i) if units==0:ds("UNITS:",15,33,(255,0,0),SKY) ds((str(FIELDS[Y][X][tour].count(i))+" "+UNITS[i][0]),15,51+units*17,TXT,SKY) if BASES[tour][0]==Y and BASES[tour][1]==X:actions.append(1) for i in range(len(FIELDS[Y][X][tour])): if FIELDS[Y][X][tour].count(FIELDS[Y][X][tour][i])>2 and 2 not in actions:actions.append(2) if i in FIELDS[Y][X][tour] and 0 not in actions:actions.append(0) for i in range(len(actions)):ds(ACTIONS[actions[i]],220-len(ACTIONS[actions[i]])*5,80+i*30,TXT,SKY) while k(4) or k(17):1 while 1: if k(1) or k(2) or second: rect(210-len(ACTIONS[actions[action]])*5,80+action*30,10,18,SKY) rect(220+len(ACTIONS[actions[action]])*5,80+action*30,10,18,SKY) action,second=(action+(k(2)-k(1)))%len(actions),0 ds("[",210-len(ACTIONS[actions[action]])*5,80+action*30,(255,0,0),SKY) ds("]",220+len(ACTIONS[actions[action]])*5,80+action*30,(255,0,0),SKY) while k(1) or k(2):1 elif k(4) or k(17): if k(4) and actions[action]==0: second=1 rect(180,50,90,120,SKY) ds("MOVE:",180,35,(255,0,0),SKY) ds("[OK]",150,65,(255,0,0),SKY) ds("to valide",200,65,TXT,SKY) ds("[CLEAR]",140,85,(255,0,0),SKY) ds("to quit",220,85,TXT,SKY) while k(4):1 while not k(4): if k(1) or k(2) or second: draw_arrow(20+len(str(FIELDS[Y][X][tour].count(move))+" "+UNITS[move][0])*10,57+move*17,SKY) move,second=(move+(k(2)-k(1)))%(units+1),0 draw_arrow(20+len(str(FIELDS[Y][X][tour].count(move))+" "+UNITS[move][0])*10,57+move*17,(255,0,0)) while k(1) or k(2):1 if k(17): move=-1 break if k(4) and actions[action]==1: generate=1 if k(4) and actions[action]==2: fuse=1 brak=1 if brak:break if brak:break # if k(4) and move>-1: # if move==0 or move==1 or move==4 or move==5: # while not k(4): # if k(0) or k(1) or k(2) or k(3): if brek:break #soldat,tank,avion,bateau #regiment,char,chasseur,cuirasse