flappy-bird-game-screens

I posted this as a hypothetical assignment for my Creative Technologies students at UU Magee for their Creative Coding modules but thought it can come here too.

What is the average #flappybird score? I can’t get past 3 points and gave up after a few attempts as I’m not your classic game player type. Players can share (brag) their scores to the rest of the world.

Fri Feb 07 10:17:09 +0000 2014|getting better ! :) I scored 32 pts in #flapflap!!! -> http://t.co/0JYC2DCEqV
Fri Feb 07 10:17:11 +0000 2014|OMG! I scored 44 pts in #flapflap!!! -> http://t.co/nveTSpT0Wf
Fri Feb 07 10:17:19 +0000 2014|OMG! I scored 28 pts in #flapflap!!! -> http://t.co/HB3CoKhXdK
Fri Feb 07 10:17:24 +0000 2014|OMG! I scored 5 pts in #flapflap!!! -> http://t.co/2Bdmtq1bMG
Fri Feb 07 10:17:26 +0000 2014|OMG! I scored 9 pts in #flapflap!!! -> http://t.co/9kN0NIam2A
Fri Feb 07 10:17:27 +0000 2014|OMG! I scored 16 pts in #flapflap!!! -> http://t.co/nQKvmvGWN9
Fri Feb 07 10:17:40 +0000 2014|OMG! I scored 10 pts in #flapflap!!! -> http://t.co/Kw7FpwCEi8
Fri Feb 07 10:17:53 +0000 2014|OMG! I scored 21 pts in #flapflap!!! -> http://t.co/mMCe1ZB4OI
Fri Feb 07 10:17:54 +0000 2014|OMG! I scored 27 pts in #flapflap!!! -> http://t.co/wyzD01eYl1
Fri Feb 07 10:17:58 +0000 2014|OMG! I scored 33 pts in #flapflap!!! -> http://t.co/DXgVmKcmd8
Fri Feb 07 10:18:01 +0000 2014|OMG! I scored 3 pts in #flapflap!!! -> http://t.co/ocQgVUIlsj
Fri Feb 07 10:18:03 +0000 2014|OMG! I scored 9 pts in #flapflap!!! -> http://t.co/peCDbJFPH1

As the output is pretty uniformed I set a SpringXD stream to pull the scores from Twitter as they happened.

With a quick hack around with Python (Java is my main language, Python is second for stuff around the edges) I came up with this:

#flappyanalytics.py
#import the regular expressions library
import re
# create the function to calculate the average score
# all we do is divide the sum of the array by the number of elements in it
def getmean(scorearray):
 return sum(scorearray) / float(len(scorearray))
# function to get the minimum score
def getmin(scorearray):
 return min(scorearray)
# function to get the maximum score
def getmax(scorearray):
 return max(scorearray)
# MAIN PROGRAM NOW STARTS.....
# create a regular expression to look for "123 pts" in the text
r = re.compile('([0-9]+) pts')
# open the file flappybird.out
file = open('flappybird.out')
# create an empty list array
scorearray = []
# open the file and iterate each line
for line in file:
 try:
 # extract the score from the line
 scorearray.append(int(r.findall(line)[0]))
 except:
 w = 0
 # if it borks on the line just ignore it
# create a new array from lowest to highest scores, we'll need this 
# for the interquartile mean.
sortedarray = sorted(scorearray)
# define a quartile count, total size of the array divided by 4
qcount = int(len(sortedarray)/4)
# print the min, max and mean scores 
print 'Min: ', getmin(scorearray)
print 'Max: ', getmax(scorearray)
print 'Avg: ', getmean(scorearray)
# print the interquartile range average (q2 + q3 scores)
# this eliminates the outliers and gives a more realistic mean
print 'IQM: ', getmean(sortedarray[qcount:qcount*3])

It’s not the most elegant thing in the world but it does work and for 20 minutes at lunchtime, well that’s all I really wanted…..

Min: 0
Max: 99999999999
Avg: 75570257.1496
IQM: 16.3323699422

 

Advertisements