-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathSnakes&Ladder.py
51 lines (40 loc) · 1.56 KB
/
Snakes&Ladder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Enter your code here. Read input from STDIN. Print output to STDOUT
T=input()
def gamePlay(dice,position,ladders,snakes):
ladders.sort()
snakes.sort()
ladderLow=[ladders[i][0] for i in range(len(ladders))]
snakesHead=[snakes[i][0] for i in range(len(snakes))]
count=0
while (position<=98):
roll=max(dice)
position+=roll
if position in snakesHead and roll!=1:
roll-=1
if position in snakesHead and roll==1:
position = snakes[snakesHead.index(position)][1]
if position in ladderLow:
position= ladders[ladderLow.index(position)][1]
count+=1
print snakesHead
print ladderLow
print "count ="+str(count)
print "position="+str(position)
print "position="+str(position)
return count
for testCase in range(T):
N=input()
ladders=[raw_input().split() for n in range(N)]
M=input()
snakes=[raw_input().split() for m in range(M)]
position=1
dice=[1,2,3,4,5,6]
#Select the higher number
#Check if there's a snake head
#if there's a snake head go for the next highest number
#if there's no snake head go for another roll and make a count of the step.
#if there's a ladder bottom in the position, change the position and make a count
#make sure the position reaches till 98.
#steps=0
maxCount=gamePlay(dice,position,ladders,snakes)
print maxCount