Please welcome today’s guest writer, Tony Ditta. Tony graduated in 2012 with majors in mathematics and economics. He now lives in Chicago and is pursuing graduate study in economics.

Abby said I could write “500-800 words about anything under the sun,” so I wrote a computer game in which you play Rock, Paper, Scissors against a computer, but you always win. It’s called “Rock, Paper, Scissors But You Always Win,” or “RPSBYAW” for short. Here’s a link to an executable file you can download and play.

It’s a pretty fun game. It’s not going to, like, knock your socks off, but it feels good to win. And you always win.

And here’s the thing: people pay to watch the Harlem Globetrotters, and they always win. People watch Scooby-Doo mysteries even though they know the gang is going to solve it within the next twenty minutes. You know that your life is going to end in death, but you live your life in the meantime. Why? Because it’s about the journey not the destination.

And another thing: while you play RPSBYAW, you should listen to the podcast I make with some of my friends. It’s called “Here’s My Number, So Call Me Ishmael,” and it’s very good (iTunes link and Libsyn link). It’s a cultural trivia show that deliberately gets lost in the weeds—deliberately misses the forest for the trees, and in doing so finds some very interesting trees. It’s funny and charming and Post Calvin writers Bart Tocci and Lauren Boersma are each featured in an episode.

The source code for RPSBYAW is included below:

# made by Tony Ditta with special help from this tutorial:
#     http://www.python-course.eu/python_tkinter.php

from tkinter import *

class App:
   def __init__(self, master):
      # the tkinter library uses some ‘master’ and ‘slave’ notation,
      # which I find a little troubling.
      frame = Frame(master)
      frame.pack(expand = True)

      Label(frame, text = “Welcome to RPSBYAW!”).pack()

      self.result_string = StringVar()
      self.result_string.set(“\nSelect an option from below.\n”)

      Label(frame, textvariable = self.result_string).pack()

      # I thought about starting at self.wins = 1 (because everyone is a
      # winner), but I think people will feel more satisfied if they
      # actually EARN all their wins.
      self.wins = 0
      self.wins_string = StringVar()
      self.wins_string.set(“Wins:\t” + str(self.wins))

      Label(frame, textvariable = self.wins_string).pack()

      Label(frame, text = “Losses:\t0”).pack()

      self.game = {“Rock”     : “Scissors”,
                    “Paper”    : “Rock”,
                    “Scissors” : “Paper”}

      options = list(self.game.keys())

      commands = dict()

      # these next three lines are begging for iteration, but there’s
      # something about the mutability of these lambdas or SOMETHING
      # that’s not working as expected. when I iterate over the
      # assignment, all of them are assigned to the value from the last
      # step of the iteration. I tried embedding them in a list because
      # lists are immutable, but they can’t be stored directly in a list
      # because functions are not iterable, and when I store them in an
      # array the same problem as above arises. maybe somebody who knows
      # more about Python can figure it out.
      commands[options[0]] = lambda : self.make_choice(options[0])
      commands[options[1]] = lambda : self.make_choice(options[1])
      commands[options[2]] = lambda : self.make_choice(options[2])

      # I could’ve chosen the ‘side = “left”‘ option in the pack() call,
      # but I always want to be on the right side of history.
      for opt in options:
         Button(frame,
               text = opt,
               command = commands[opt]).pack(side = “right”,
                                             padx = 10,
                                             pady = 10)
   def make_choice(self, option):
      # the ‘I’ of ‘AI’ is used very loosely here.
      result = “You chose ” + option.upper() + “.\n” + \
               “The AI chose ” + self.game[option].upper() + “.\n” + \
               “That means… YOU WIN!”
      self.result_string.set(result)

      self.wins += 1
      self.wins_string.set(“Wins:\t” + str(self.wins))

 

root = Tk()
root.title(“RPSBYAW”)
# note that the dimensions have been set to the visually satisfying
# ‘golden ratio.’ you’ll find that many of the features of this
# interface have been carefully crafted to please the eye.
root.minsize(width = 324, height = 200)
app = App(root)
root.mainloop()

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Similar posts

“””Art”””
by Tony Ditta, April 17, 2019
Chess Bots
by Tony Ditta, August 17, 2018
Blessed are the IT Professionals
by Nick Meekhof, May 26, 2018
Scroll Down
by Elaine Schnabel, September 11, 2014
Silver, and Gold, and Dross
by Kyric Koning, April 30, 2018

post calvin direct

Get new posts from Tony Ditta delivered straight to your inbox.

Do NOT follow this link or you will be banned from the site!