alt text

Let's play the Frog Jumping game!

The YouTube video teaches us the rules of this game.

In [1]:
#Import Youtube Video
from IPython.display import YouTubeVideo
YouTubeVideo('R8wkhae4Pvg')
Out[1]:

Now you play the Frog Jumping game!

In [3]:
%%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>
  • Reset
  • Undo
  • Your moves: 0
Step Number Current Position Move

Below is the code that takes YOUR move sequence, and applies it to the starting position

Feel free to ignore this :-)

In [4]:
def play_game(starting_position, move_sequence):
    
    Alist=[]
    Blist=[]
    Empty=0
    totalmoves=0
    counter=0
    flag=0

    for i in range(0,len(starting_position)):
        if starting_position[i]=='A':
            counter+=1
            Alist.append(counter)
        if starting_position[i]=='B':
            counter+=1
            Blist.append(counter)
        if starting_position[i]=='_':
            counter+=1
            Empty=counter

    startAlist=list.copy(Alist)
    startBlist=list.copy(Blist)
    startEmpty=Empty

    for i in range(0,len(move_sequence)):
        if move_sequence[i]=='A':
            totalmoves+=1
            print("")
            if Empty-1 in Alist:
                Alist.remove(Empty-1)
                Alist.append(Empty)
                Empty=Empty-1
            elif Empty-2 in Alist and Empty-1 in Blist:
                Alist.remove(Empty-2)
                Alist.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]=='B': 
            totalmoves+=1
            print("")
            if Empty+1 in Blist:
                Blist.remove(Empty+1)
                Blist.append(Empty)
                Empty=Empty+1
            elif Empty+2 in Blist and Empty+1 in Alist:
                Blist.remove(Empty+2)
                Blist.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]=='A' or move_sequence[i]=='B':
            for j in range(0,counter+1):
                if j in Alist: print("A ", end = " ") 
                elif j in Blist: print("B ", end = " ")
                elif j == Empty: print("_ ", end = " ") 
                else: print("", end = " ")
            print("")
    
    print("")
    
    startAlist.sort()
    startBlist.sort()
    Alist.sort()
    Blist.sort()
    
    if flag==0:
        if startAlist==Blist and startBlist==Alist 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!")
        

Input your STARTING POSITION below, with team names A and B

For example, with four people on each team, write down AAAA _ BBBB

In [5]:
starting_position = 'AA_BB'

Now input your MOVE SEQUENCE, to try to solve the game

For example, with two people on each team, one solution is A BB AA BB A

In [6]:
move_sequence = 'A BB AA BB A '
In [7]:
play_game(starting_position, move_sequence)
 A  _  A  B  B  

 A  B  A  _  B  

 A  B  A  B  _  

 A  B  _  B  A  

 _  B  A  B  A  

 B  _  A  B  A  

 B  B  A  _  A  

 B  B  _  A  A  

Congratulations! You have solved the problem in 8 total moves

alt text