- Reset
- Undo
- Your moves: 0
#Import Youtube Video
from IPython.display import YouTubeVideo
YouTubeVideo('R8wkhae4Pvg')
%%html
<link rel="stylesheet" href="style.css">
<div class="frogNum">
<label for="frogs"><strong>Choose number of frogs: </strong></label>
<select name="frogs" id="frogNumberSelector">
<option value="2" selected>4 Frogs</option>
<option value="3">6 Frogs</option>
<option value="4">8 Frogs</option>
</select>
</div>
<div class="mainGrid">
<ul id="frogList" class="frogGrid">
<li class="btns" onclick="resetFrogs()"><span>Reset</span></li>
<li class="btns" onclick="undo()"><span>Undo</span></li>
<li class="counter">Your moves: <span id="counter">0</span></li>
</ul>
</div>
<div>
<table id="moveTable">
<tr>
<th>Step Number</th>
<th>Current Position</th>
<th>Move</th>
</tr>
</table>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E="
crossorigin="anonymous"></script>
<script src="main.js"></script>
Step Number | Current Position | Move |
---|
def play_game(starting_position, move_sequence):
Rlist=[]
Glist=[]
Empty=0
totalmoves=0
counter=0
flag=0
for i in range(0,len(starting_position)):
if starting_position[i]=='R':
counter+=1
Rlist.append(counter)
if starting_position[i]=='G':
counter+=1
Glist.append(counter)
if starting_position[i]=='_':
counter+=1
Empty=counter
startRlist=list.copy(Rlist)
startGlist=list.copy(Glist)
startEmpty=Empty
for i in range(0,len(move_sequence)):
if move_sequence[i]=='R':
totalmoves+=1
print("")
if Empty-1 in Rlist:
Rlist.remove(Empty-1)
Rlist.append(Empty)
Empty=Empty-1
elif Empty-2 in Rlist and Empty-1 in Glist:
Rlist.remove(Empty-2)
Rlist.append(Empty)
Empty=Empty-2
else:
print("")
print("ERROR: sorry you made a mistake after", totalmoves, "total moves")
flag=1
break
if move_sequence[i]=='G':
totalmoves+=1
print("")
if Empty+1 in Glist:
Glist.remove(Empty+1)
Glist.append(Empty)
Empty=Empty+1
elif Empty+2 in Glist and Empty+1 in Rlist:
Glist.remove(Empty+2)
Glist.append(Empty)
Empty=Empty+2
else:
print("")
print("ERROR: sorry you made a mistake after", totalmoves, "total moves")
flag=1
break
if move_sequence[i]=='R' or move_sequence[i]=='G':
for j in range(0,counter+1):
if j in Rlist: print("R ", end = " ")
elif j in Glist: print("G ", end = " ")
elif j == Empty: print("_ ", end = " ")
else: print("", end = " ")
print("")
print("")
startRlist.sort()
startGlist.sort()
Rlist.sort()
Glist.sort()
if flag==0:
if startRlist==Glist and startGlist==Rlist and startEmpty==Empty:
print("Congratulations! You have solved the problem in", totalmoves, "total moves")
else:
print("You have currently made", totalmoves, "total moves. Keep going!")
starting_position = 'RR_GG'
move_sequence = 'G RR GG RR G'
play_game(starting_position, move_sequence)
R R G _ G R _ G R G _ R G R G G R _ R G G R G R _ G R G _ R G _ G R R G G _ R R Congratulations! You have solved the problem in 8 total moves