Hello,
I have been working on learning Python and I have been writing a game(CLUI not GUI) that has gone through a few phases. It started out as a 3-4-5 variant assuming 3 rows with 3 objects in the first row, 4 in the second, and 5 in the third and with 2 players. The person to take the last object was the loser.
Now the game has an MxN playing field where you pick the dimensions and you also get to pick the number of players. This is where I have ran into some difficulties:
Currently the game will run until someone loses and then the game ends. I would like the game to exclude the loser and continue on until one player remains. Also, I would one day like to have it so that it is one player and the computer (comp doesn't need to make brilliant moves only valid moves.)
If someone could help me with either of these issues I would be greatly appreciative!!! (The code at the end that is commented out is leftover from when the game was 2 players only)
PlayingField = []
#Setting up the Field
def Setup (rows, start):
i=0
while (i<rows):
j=0
temp=[]
while(j<start):
temp.append(1)
j=j+1
PlayingField.append(temp)
start=start+1
i=i+1
#Displaying the Field
def Display (rows, start):
i=0
l=1
while(i<rows):
j=0
temp=""
while(j<start):
if (PlayingField[i][j] == 1):
temp=temp+"o"
else:
temp=temp+" "
j=j+1
print(l,temp)
start=start+1
i=i+1
l=l+1
print()
#Detecting When the Game is Over
def Coincheck(rows, start):
i=0
while (i<rows):
j=0
while(j<start):
if (PlayingField[i][j]==1):
return (1)
j=j+1
start=start+1
i=i+1
return(0)
#Naming the Game and Getting Players Names
print ("Welcome to Adama's high and lofty game!")
players=int(input("how many players "))
names=[]
k=1
PC=players
while(players>0):
print("Player",k,"please enter your name ")
aa=str(input())
names.append(aa)
k=k+1
players=players-1
#Getting the Number of Rows in the Playing Field
error=1
while (error==1):
a=int(input("Enter the number of rows you would like: "))
if (a==0):
error=1
print()
print("Please choose 1 or more rows!")
print()
else:
error=0
#Getting the Number of Objects in Beginning Row
error=1
while (error==1):
b=int(input("Enter number of objects in beginning row: "))
if (b==0):
error=1
print()
print("Please choose 1 or more objects for row 1!")
else:
error=0
print()
Setup(a,b)
Display(a,b)
# Turn rotation
c=0
while (Coincheck (a,b)==1):
print ("Your Turn ",names[c])
c=c+1
if (c==PC):
c=0
else:
(c==c)
#Number of rows to be removed
error=1
while (error==1):
x=int(input("Enter the row of the object you wish to remove: "))
x=x-1
if (x==-1):
error=1
print("Please choose an existing row! ")
elif ((x+1)>a):
error=1
print("Not a vaild move! Please choose an extisting row!")
elif (sum(PlayingField[x])==0):
error=1
print("All objects have been removed from this row!")
else:
error=0
#Number of Starting Column Removal
error=1
while (error==1):
y=int(input("Enter the column where you wish to begin: "))
y=y-1
if (y==-1):
error=1
print("There is no 0 column! ")
elif (y+1>len(PlayingField[x])):
error=1
print()
print("There are not",y+1, "columns so choose again")
print()
elif (PlayingField[x][y]==0):
error=1
print("Please choose from an object that is in play ")
else:
error=0
#Number of Objects to be Removed
error=1
while (error==1):
z=int(input("Enter the number of objects to remove: "))
if (z==0):
error=1
print ("Please choose 1 or more objects! ")
elif (z>sum(PlayingField[x][y:(z+y+1)])):
error=1
print ("There are not this many objects, try again! ")
else:
error=0
n=0,
PlayingField[x][y:z] = n * z
print()
Display(a,b)
#Displaying the Loser's and Winner's Names
#if (c%2==1):
# print ("Game Over " + name1 + " You Lose! " + name2 + " YOU ARE THE WINNER!!!")
#else:
# print ("Game Over " + name2 + " You Lose! " + name1 + " YOU ARE THE WINNER!!!")