ABSP, Ch 11, Practice Project #3

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s