How can I make the code in this function more efficient?
up vote
0
down vote
favorite
This function is part of a python board game program. The game is a board game with chests and bandits hidden throughout the board. The function is dedicated to the "easy" section of the game (where it is a 8x8 grid).
def easy_level(Coins):
#This function is for the movement of the game in easy difficulty
while True:
oldcurrent=current
boardeasy[oldcurrent[0]][oldcurrent[1]]='*'
table_game_easy()
boardeasy[oldcurrent[0]][oldcurrent[1]]=' '
n = input('Enter the direction followed by the number Ex:Up 5 , Number should be < 8 n')
n=n.split()
if n[0].lower() not in ['up','left','down','right']:#Validates input
print('Wrong command, please input again')
continue
elif n[0].lower()=='up':
up(int(n[1].lower()),8)#Boundary is set to 8 as the 'easy' grid is a 8^8
elif n[0].lower()=='down':
down(int(n[1].lower()),8)
elif n[0].lower()=='left':
left(int(n[1].lower()),8)
elif n[0].lower()=='right':
right(int(n[1].lower()),8)
print("5 chests left")
print("8 bandits left")
print("Coins:",Coins)#Acts as a counter, displays the number of coins that the player has
if current[0] == Treasure1_Row and current[1] == Treasure1_Col
or current[0] == Treasure2_Row and current[1] == Treasure2_Col
or current[0] == Treasure3_Row and current[1] == Treasure3_Col
or current[0] == Treasure4_Row and current[1] == Treasure4_Col
or current[0] == Treasure5_Row and current[1] == Treasure5_Col
or current[0] == Treasure6_Row and current[1] == Treasure6_Col
or current[0] == Treasure7_Row and current[1] == Treasure7_Col
or current[0] == Treasure8_Row and current[1] == Treasure8_Col
or current[0] == Treasure9_Row and current[1] == Treasure9_Col
or current[0] == Treasure10_Row and current[1] == Treasure10_Col:
print("Hooray! You have found booty! +10 gold")
Coins = Coins+10 #Adds an additional 10 points
print("Coins:",Coins)
if current[0] == Bandit1_Row and current[1] == Bandit1_Col
or current[0] == Bandit2_Row and current[1] == Bandit2_Col
or current[0] == Bandit3_Row and current[1] == Bandit3_Col
or current[0] == Bandit4_Row and current[1] == Bandit4_Col
or current[0] == Bandit5_Row and current[1] == Bandit5_Col:
print("Oh no! You have landed on a bandit...they steal all your coins!")
Coins = Coins-Coins #Removes all coins
print("Coins:",Coins)
boardeasy[current[0]][current[1]]='*'#sets value to players position
python game
migrated from stackoverflow.com 1 hour ago
This question came from our site for professional and enthusiast programmers.
add a comment |
up vote
0
down vote
favorite
This function is part of a python board game program. The game is a board game with chests and bandits hidden throughout the board. The function is dedicated to the "easy" section of the game (where it is a 8x8 grid).
def easy_level(Coins):
#This function is for the movement of the game in easy difficulty
while True:
oldcurrent=current
boardeasy[oldcurrent[0]][oldcurrent[1]]='*'
table_game_easy()
boardeasy[oldcurrent[0]][oldcurrent[1]]=' '
n = input('Enter the direction followed by the number Ex:Up 5 , Number should be < 8 n')
n=n.split()
if n[0].lower() not in ['up','left','down','right']:#Validates input
print('Wrong command, please input again')
continue
elif n[0].lower()=='up':
up(int(n[1].lower()),8)#Boundary is set to 8 as the 'easy' grid is a 8^8
elif n[0].lower()=='down':
down(int(n[1].lower()),8)
elif n[0].lower()=='left':
left(int(n[1].lower()),8)
elif n[0].lower()=='right':
right(int(n[1].lower()),8)
print("5 chests left")
print("8 bandits left")
print("Coins:",Coins)#Acts as a counter, displays the number of coins that the player has
if current[0] == Treasure1_Row and current[1] == Treasure1_Col
or current[0] == Treasure2_Row and current[1] == Treasure2_Col
or current[0] == Treasure3_Row and current[1] == Treasure3_Col
or current[0] == Treasure4_Row and current[1] == Treasure4_Col
or current[0] == Treasure5_Row and current[1] == Treasure5_Col
or current[0] == Treasure6_Row and current[1] == Treasure6_Col
or current[0] == Treasure7_Row and current[1] == Treasure7_Col
or current[0] == Treasure8_Row and current[1] == Treasure8_Col
or current[0] == Treasure9_Row and current[1] == Treasure9_Col
or current[0] == Treasure10_Row and current[1] == Treasure10_Col:
print("Hooray! You have found booty! +10 gold")
Coins = Coins+10 #Adds an additional 10 points
print("Coins:",Coins)
if current[0] == Bandit1_Row and current[1] == Bandit1_Col
or current[0] == Bandit2_Row and current[1] == Bandit2_Col
or current[0] == Bandit3_Row and current[1] == Bandit3_Col
or current[0] == Bandit4_Row and current[1] == Bandit4_Col
or current[0] == Bandit5_Row and current[1] == Bandit5_Col:
print("Oh no! You have landed on a bandit...they steal all your coins!")
Coins = Coins-Coins #Removes all coins
print("Coins:",Coins)
boardeasy[current[0]][current[1]]='*'#sets value to players position
python game
migrated from stackoverflow.com 1 hour ago
This question came from our site for professional and enthusiast programmers.
2
what do you mean more efficient?
– SuperStew
Nov 14 at 0:00
1
Reduce the amount of code needed perhaps?
– J.Peggy
Nov 14 at 0:01
How can I make the code in this function more efficient?
isn't a good title for Code Review because stateing your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
– Heslacher
36 mins ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This function is part of a python board game program. The game is a board game with chests and bandits hidden throughout the board. The function is dedicated to the "easy" section of the game (where it is a 8x8 grid).
def easy_level(Coins):
#This function is for the movement of the game in easy difficulty
while True:
oldcurrent=current
boardeasy[oldcurrent[0]][oldcurrent[1]]='*'
table_game_easy()
boardeasy[oldcurrent[0]][oldcurrent[1]]=' '
n = input('Enter the direction followed by the number Ex:Up 5 , Number should be < 8 n')
n=n.split()
if n[0].lower() not in ['up','left','down','right']:#Validates input
print('Wrong command, please input again')
continue
elif n[0].lower()=='up':
up(int(n[1].lower()),8)#Boundary is set to 8 as the 'easy' grid is a 8^8
elif n[0].lower()=='down':
down(int(n[1].lower()),8)
elif n[0].lower()=='left':
left(int(n[1].lower()),8)
elif n[0].lower()=='right':
right(int(n[1].lower()),8)
print("5 chests left")
print("8 bandits left")
print("Coins:",Coins)#Acts as a counter, displays the number of coins that the player has
if current[0] == Treasure1_Row and current[1] == Treasure1_Col
or current[0] == Treasure2_Row and current[1] == Treasure2_Col
or current[0] == Treasure3_Row and current[1] == Treasure3_Col
or current[0] == Treasure4_Row and current[1] == Treasure4_Col
or current[0] == Treasure5_Row and current[1] == Treasure5_Col
or current[0] == Treasure6_Row and current[1] == Treasure6_Col
or current[0] == Treasure7_Row and current[1] == Treasure7_Col
or current[0] == Treasure8_Row and current[1] == Treasure8_Col
or current[0] == Treasure9_Row and current[1] == Treasure9_Col
or current[0] == Treasure10_Row and current[1] == Treasure10_Col:
print("Hooray! You have found booty! +10 gold")
Coins = Coins+10 #Adds an additional 10 points
print("Coins:",Coins)
if current[0] == Bandit1_Row and current[1] == Bandit1_Col
or current[0] == Bandit2_Row and current[1] == Bandit2_Col
or current[0] == Bandit3_Row and current[1] == Bandit3_Col
or current[0] == Bandit4_Row and current[1] == Bandit4_Col
or current[0] == Bandit5_Row and current[1] == Bandit5_Col:
print("Oh no! You have landed on a bandit...they steal all your coins!")
Coins = Coins-Coins #Removes all coins
print("Coins:",Coins)
boardeasy[current[0]][current[1]]='*'#sets value to players position
python game
This function is part of a python board game program. The game is a board game with chests and bandits hidden throughout the board. The function is dedicated to the "easy" section of the game (where it is a 8x8 grid).
def easy_level(Coins):
#This function is for the movement of the game in easy difficulty
while True:
oldcurrent=current
boardeasy[oldcurrent[0]][oldcurrent[1]]='*'
table_game_easy()
boardeasy[oldcurrent[0]][oldcurrent[1]]=' '
n = input('Enter the direction followed by the number Ex:Up 5 , Number should be < 8 n')
n=n.split()
if n[0].lower() not in ['up','left','down','right']:#Validates input
print('Wrong command, please input again')
continue
elif n[0].lower()=='up':
up(int(n[1].lower()),8)#Boundary is set to 8 as the 'easy' grid is a 8^8
elif n[0].lower()=='down':
down(int(n[1].lower()),8)
elif n[0].lower()=='left':
left(int(n[1].lower()),8)
elif n[0].lower()=='right':
right(int(n[1].lower()),8)
print("5 chests left")
print("8 bandits left")
print("Coins:",Coins)#Acts as a counter, displays the number of coins that the player has
if current[0] == Treasure1_Row and current[1] == Treasure1_Col
or current[0] == Treasure2_Row and current[1] == Treasure2_Col
or current[0] == Treasure3_Row and current[1] == Treasure3_Col
or current[0] == Treasure4_Row and current[1] == Treasure4_Col
or current[0] == Treasure5_Row and current[1] == Treasure5_Col
or current[0] == Treasure6_Row and current[1] == Treasure6_Col
or current[0] == Treasure7_Row and current[1] == Treasure7_Col
or current[0] == Treasure8_Row and current[1] == Treasure8_Col
or current[0] == Treasure9_Row and current[1] == Treasure9_Col
or current[0] == Treasure10_Row and current[1] == Treasure10_Col:
print("Hooray! You have found booty! +10 gold")
Coins = Coins+10 #Adds an additional 10 points
print("Coins:",Coins)
if current[0] == Bandit1_Row and current[1] == Bandit1_Col
or current[0] == Bandit2_Row and current[1] == Bandit2_Col
or current[0] == Bandit3_Row and current[1] == Bandit3_Col
or current[0] == Bandit4_Row and current[1] == Bandit4_Col
or current[0] == Bandit5_Row and current[1] == Bandit5_Col:
print("Oh no! You have landed on a bandit...they steal all your coins!")
Coins = Coins-Coins #Removes all coins
print("Coins:",Coins)
boardeasy[current[0]][current[1]]='*'#sets value to players position
python game
python game
edited 38 mins ago
Heslacher
44.6k460154
44.6k460154
asked Nov 13 at 23:52
J.Peggy
migrated from stackoverflow.com 1 hour ago
This question came from our site for professional and enthusiast programmers.
migrated from stackoverflow.com 1 hour ago
This question came from our site for professional and enthusiast programmers.
2
what do you mean more efficient?
– SuperStew
Nov 14 at 0:00
1
Reduce the amount of code needed perhaps?
– J.Peggy
Nov 14 at 0:01
How can I make the code in this function more efficient?
isn't a good title for Code Review because stateing your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
– Heslacher
36 mins ago
add a comment |
2
what do you mean more efficient?
– SuperStew
Nov 14 at 0:00
1
Reduce the amount of code needed perhaps?
– J.Peggy
Nov 14 at 0:01
How can I make the code in this function more efficient?
isn't a good title for Code Review because stateing your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.
– Heslacher
36 mins ago
2
2
what do you mean more efficient?
– SuperStew
Nov 14 at 0:00
what do you mean more efficient?
– SuperStew
Nov 14 at 0:00
1
1
Reduce the amount of code needed perhaps?
– J.Peggy
Nov 14 at 0:01
Reduce the amount of code needed perhaps?
– J.Peggy
Nov 14 at 0:01
How can I make the code in this function more efficient?
isn't a good title for Code Review because stateing your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.– Heslacher
36 mins ago
How can I make the code in this function more efficient?
isn't a good title for Code Review because stateing your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.– Heslacher
36 mins ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208206%2fhow-can-i-make-the-code-in-this-function-more-efficient%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
what do you mean more efficient?
– SuperStew
Nov 14 at 0:00
1
Reduce the amount of code needed perhaps?
– J.Peggy
Nov 14 at 0:01
How can I make the code in this function more efficient?
isn't a good title for Code Review because stateing your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly.– Heslacher
36 mins ago