MENU

Fun & Interesting

Animated Python: 2D Lists and Connect Four

Concepts Illuminated 2,405 2 years ago
Video Not Working? Fix It Now

This video animates the execution of the Python functions which provide the core features of the game Connect Four. Viewers can see how the computer executes the code step by step and see the contents of the variables change as the computer executes the operations. The key components illustrated are two-dimensional lists, functions, conditionals, and variables. Another way to visualize code running is https://pythontutor.com (which also has versions for C++, Java, and other programming languages). Playlist of Visualizations: - https://www.youtube.com/playlist?list=PLDs5gxU1J5CLKlTjZKLtPau7DFrAnDRHD Animations made by Kaylee L with Manim Community edition (https://www.manim.community/) - https://github.com/kjlubick/manim_ace Narration by James K. Background music from YouTube Audio Library (https://youtube.com/audiolibrary) - Siestita by Quincas Moreira - The Trapezist by Quincas Moreira - End of the Rainbow by Quincas Moreira Sound effect from YouTube Audio Library - Magic Chime 0:00 - Connect Four overview 0:26 - Defining the make_board and add_token functions 0:50 - Calling make_board to make a traditional 7 wide by 6 high board 1:41 - Multiplying a list by an integer? 2:40 - make_board for range loop finishes, completing the two-dimensional list 3:17 - Calling add_token to simulate players taking their turns 3:51 - Extracting an item from a two-dimensional list (in a condition) 5:41 - Updating an item in a two-dimensional list (at the bottom of the board) 7:59 - Putting one piece on top of an existing piece 9:25 - All pieces are in place, ready to look for winners horizontally 10:00 - Nested for loops to go through all rows and (most) columns 11:35 - winner_horizontal has found a non-empty piece 12:31 - short-circuit evaluation 13:33 - Four-in-a-row found! 14:20 - Why the minus 3 in the range stop parameter? 15:01 - winner_vertical code is similar to the winner_horizontal code 15:45 - winner_diagonal1 (down to the right) code combines horizontal and vertical 16:02 - winner_diagonal2 (down to the left) code requires some slight changes. 16:32 - What else is required to finish coding the game?

Comment