Skip to content

Instantly share code, notes, and snippets.

def solve_puzzle(self):
"""
Generate a solution string for a puzzle
Updates the puzzle and returns a move string
"""
total_moves = ""
moves = ""
if self.lower_row_invariant(0, 0):
return moves
"""
Loyd's Fifteen puzzle - solver and visualizer
project by TG 13/08/2015
poc_fifteen_gui and Puzzle class provided by instructors
and modified (random shuffle method added)
Note that solved configuration has the blank (zero) tile in upper left
Use the arrows key to swap this tile with its neighbors.
"""
Word Wrangler game
WordWranglerGUI class and WordWrangler class provided by instructors
project by TG 26/06/2015
starts at line 195
enable pop-up windows!!
hit play to start
"""
Monte Carlo metod Tic-Tac-Toe Player
project by TG 12/06/2015
poc_ttt_provided and poc_ttt_gui provided by instructors
enable pop-up windows!!
deacrease NTRIALS(line 20) to reduce AI and speed up AI moves
player can change the board size (line 23)
"""
Zombie Apocalypse
-TG 17/07/2015(modifed oct/2015)
-project for PoC course by Rice University
https://www.coursera.org/course/principlescomputing2
-Zombie template
http://www.codeskulptor.org/#poc_zombie_template.py
"""
Clone of 2048 game
http://2048game.com/
- click Play to Start
- project for PoC course by Rice University
https://www.coursera.org/course/principlescomputing1
- 2048 template
http://www.codeskulptor.org/#poc_2048_template.py
"""
RiceRocks (Asteroids) the Game
An Introduction to Interactive Programming in Python
by Joe Warren, Scott Rixner, John Greiner, Stephen Wong -- Rice Univercity
project by TG
"""
import simplegui
import math
import random
def add_item(self, click_position):
"""
Event handler to add new obstacles, humans and zombies
"""
row, col = self._simulation.get_index(click_position, CELL_SIZE)
if self._item_type == OBSTACLE:
if not self.is_occupied(row, col):
self._simulation.set_full(row, col)
elif self._item_type == ZOMBIE:
if self._simulation.is_empty(row, col):
# Function to generate all strings for the word wrangler game
def gen_all_strings(word):
"""
Generate all strings that can be composed from the letters in word
in any order.
Returns a list of all strings that can be formed from the letters
in word.
def get_best_move(board, scores):
"""
Return best move [tuple (row, column)] for the given board,
based on the given list of scores.
"""
best_moves = []
for empty_sq in board.get_empty_squares():
if best_moves:
if scores[empty_sq[0]][empty_sq[1]] > scores[best_moves[0][0]][best_moves[0][1]]:
best_moves = []