Computer Science 101

Percy

Well-Known Member
#1
Hi Guys,

I was wondering if anyone could advise on the ways one can go about learning to write programs to analyze games? In other words, write code, run the numbers, build sims etc.

What should I study? Where should I start (assume I have no prior knowledge)? Is it something you can teach yourself or is it important to attend a face-to-face course?

Whilst I realize this is a very subjective and person dependent variable, I would also be interested to hear how many man hours people think it will take to reach a practical level.

This isn’t something I intend to get to work on right away, but it would be good to have an idea of what I need to commit and prepare myself for.

Thanks in advance,

Percy
 

MangoJ

Well-Known Member
#2
If you are new to programming, the obvious first choice is that of programming language. After all, all programming languages are equivalent, and with (much) time you will find your own preferences - for the beginning I would pick a language which has a large user base (you WILL need help sometimes), has a high quality supply of software libraries, and is sufficiently easy to set up by yourself.

As a personal choice I would recommend Python. It's rather easy to set up for small scripts (quick and dirty), but is capable of handling more serious programs. It has a professional user base, lots of libraries and documentation, and is easy in practical use.

Regarding your time management: Reaching practical level from ground zero on is measured in MONTHS (depending on the problem, even YEARS).

However, unlike natural languages, once you are fairly proficient with one language, you can change new programming languages in a matter of DAYS.
 

blackjackomaha

Well-Known Member
#3
I am partial to Perl. Also a good language for scripts and has the capabilities to perform larger tasks. Python would be my second choice only because I am more intimately familiar with Perl.

Both are simple to learn...easier if you know a prior language, such as Java, C, or C++.
 

farmdoggy

Well-Known Member
#4
I will have to second Python... It's the most powerfull program that exists. I can send you my source for the blackack simulator I built, but I'll have to edit some of the comments since I changed most of the code so far, and I didn't exactly design it to be "user friendly". I also have programs built to analyze Match the Dealer and Perfect Pairs if you want.
 

farmdoggy

Well-Known Member
#5
I would start by downloading Python(x,y) (google it, it's a free download but takes up a ton of space)

Open up "Spyder" within your program once it's installed. You can google just about anything you want to know about Python.

On the right side of Spyder there is interctive display where you can search for commands that are available and what they do, such as "random". Alot of Python is knowing which modules you have to "import" in order to gain commands... For example "random" is located in numpy. Also everything in Python has a "type" which determines what you can do with it.

I would start by learning how to do basic if statements, and then learn what a "for loop" and "while loop" is, and experiment with lists and their commands. Once you can do these and generate random numbers, you can pretty much start on your programming for a blackjack simulator, but you will find it more efficient to learn how to define and use a function first.

It might be worth it to sign up for a class, but certainly not necessary... Just easier. Programming of this type is fairly easy, and I started on my blackjack sim after just 2 weeks of classes, 3 hours a week + outside assignments.

Have fun :)

Edit: A fun thing to start with might be to make a list of cards and have them "shuffled", then deal a card. Heres a function I defined to do that, just copy and paste on the left hand side of Spyder and hit "run". (Actually the bold text all needs to be tabbed over 1 before this can work including the ''', the display here is messing up my code)

from numpy import random

def create_shoe(number_of_decks):
'''
This function creates a list of standard playing cards.
The input is an integer, and the function adds this number
of decks to the list (shoe) and shuffles it.
'''
cards = range(2, 11) + ['J','Q','K','A']
single_deck = 4 * cards
shoe = number_of_decks * single_deck
random.shuffle(shoe)
return shoe


shoe=create_shoe(2) #Try changing the number inside the parenthesis later and see what happens...
card_dealt = shoe.pop()
print card_dealt

if card_dealt == "A":
print "Wow, you are awesome!"
else:
print "You Suck!"

print "There are", len(shoe), "cards left."
 

Canceler

Well-Known Member
#6
farmdoggy said:
(Actually the bold text all needs to be tabbed over 1 before this can work including the ''', the display here is messing up my code)
That's what code wrap (# button) is for! ;)

Code:
def create_shoe(number_of_decks):
   [B] '''
    This function creates a list of standard playing cards.  
    The input is an integer, and the function adds this number 
    of decks to the list (shoe) and shuffles it.
    '''
    cards = range(2, 11) + ['J','Q','K','A']
    single_deck = 4 * cards
    shoe = number_of_decks * single_deck
    random.shuffle(shoe)
    return shoe[/B]

shoe=create_shoe(2)  #Try changing the number inside the parenthesis later and see what happens...
card_dealt = shoe.pop()
print card_dealt

if card_dealt == "A":
    [B]print "Wow, you are awesome!"[/B]
else:
    [B]print "You Suck!"[/B]

print "There are", len(shoe), "cards left."
 

gronbog

Well-Known Member
#7
Beyond learning to program and the choice of programming language(s), it will help to learn about:

- probability theory: How to calculate the probability (odds) of an event occurring.
- game theory: How to analyse the properties and outcomes of games in a structured way.
- statistical theory: What the various terms are (e.g. EV, variance, standard deviation, etc) and how to apply them to the above.
- computer science related to the efficiency of algorithms vs data size. Does the time required to complete the computation grow linearly, by some logarithmic function, or even by n squared or worse as the size of the data to be analyzed grows?
- computer science related to modelling of random processes. Using only the random number function provided by the language/library you choose is usually not sufficient.
 

gronbog

Well-Known Member
#8
As for the choice of implementation language, I strongly recommend a language that can be compiled. When simulating multiple billions of hands, performance matters!
 

Gamblor

Well-Known Member
#9
As other mentions Python is good for a "quick and easy" language to learn if all your primarily interested in is doing so quick and dirty sims. In this case even Javascript might be a good choice (another popular scripting language).

If your interested in programming for more than a hobby,, probably worth learning the other big popular languages, Java, C#, and C/C++.

Many will argue that C/C++ is still the fastest language, but its also the toughest to program in. In the IT industry, it basically boils down to use Java (or maybe C#) if you want to quickly build a stable project. Use C/C++ if speed is an absolute must - but anticipate a long and buggy development cycle.

If you have the proclivity for programming, and not everyone does, it should take a less than a week to build some non-trivial program. When I first learned programming, was a able to make a simple dice simulation game within a few hours. Ah the good ol' days of Basic and Fortran.
 

Gamblor

Well-Known Member
#10
Also I personally program mostly in Java and Flex (Actionscript/Flash). I personally favor Flex of late, easier GUI implementation.
 

farmdoggy

Well-Known Member
#11
Canceler said:
That's what code wrap (# button) is for! ;)

Code:
from numpy import random

def create_shoe(number_of_decks):
    '''
    This function creates a list of standard playing cards.  
    The input is an integer, and the function adds this number 
    of decks to the list (shoe) and shuffles it.
    '''
    cards = range(2, 11) + ['J','Q','K','A']
    single_deck = 4 * cards
    shoe = number_of_decks * single_deck
    random.shuffle(shoe)
    return shoe

shoe=create_shoe(2)  #Try changing the number inside the parenthesis later and see what happens...
card_dealt = shoe.pop()
print card_dealt

if card_dealt == "A":
    print "Wow, you are awesome!"
else:
    print "You Suck!"

print "There are", len(shoe), "cards left."

Sweet! Didn't know about that... I inserted the import numpy line, and now this can just be copied and pasted in spyder.
 

Percy

Well-Known Member
#12
Guys,

Thanks very much for your thoughts.

Armed with this knowledge, I look forward to beginning my programming endeavour in the near future.:)

I will report back with my progress and I will probably have some more questions for you further down the line.

Regards,

Percy
 

Tree

Well-Known Member
#13
I may be a little late to this conversation, but I personally use either Visual Basic or Excel with VBA. Basic is an extremely simple language to use and being able to have a GUI easily helps a bunch imo.
 
Top