My solution to the Practice Project #3 in Chapter 11 of the excellent book “Automate the Boring Stuff with Python” (ABSP)
#! usr/bin/env python3 # by lorenzo - 04/10/2017 # program that plays the games 2048 by repeatedly sliding # in an up, right, down, and left pattern over and over again. import bs4 from selenium import webdriver from selenium.webdriver.common.keys import Keys import random browser = webdriver.Safari() browser.get('https://gabrielecirulli.github.io/2048/') htmlElem = browser.find_element_by_tag_name("html") print("How many moves do you want to make in the game?") numOfMoves = int(input()) for i in range(numOfMoves): htmlElem.send_keys(Keys.UP) htmlElem.send_keys(Keys.RIGHT) htmlElem.send_keys(Keys.DOWN) htmlElem.send_keys(Keys.LEFT)
Comments about the code are welcome.