Blogs
 


  Oddworld Forums > Blogs > Phylum


Rate this Entry

Snake!

Posted 01-04-2013 at 11:15 PM by Phylum
I mean Python. This is a code question so basic that it doesn't deserve a thread.

I'm writing a Python script to generate the number of distinct outcomes for the board-game Pentago, which most of you have probably never heard of. Long story short, I need to find this:

f(x) = ax + x * f(x - 1)

When x = 36 and a = 8.

I made it work, but now I'm rewriting it to be a bit more open ended so that I can plug in different sized boards.

These are the two key functions.
:
def func(num, mul):
    if num > 0:
        return mul*num + num*func(num-1)
    else:
        return 0


def runScript():
    print("How many 3x3 qudrants are in this board?")
    quads = input(input_char + " ")
    quads = int(quads)
    mul_num = quads * 2
    print()

    area = quads * 9

    print("Function will be run " + str(area) + " times")
    print("Are you sure? (y/n)")
    area = int(area)
    b = input(input_char + " ")
    if b == "y":
        out = func(area, mul_num)
        print()
        print("This Pentago board has the following number of possible outcomes:")
        print()
        print(out)
		
    else:
        print()
        print ("Ok!")
Whenever I run it I get an error in the highlighted line:
"func() is missing one positional argument: mul"

My initial thought was that I wasn't converting from a string properly, but not realising it because Python is stupid like that. I know shit all about coding in Python, but this was still much easier than the equivalent Java code as far as I'm concerned.

This is completely undocumented and will seem strange to anyone who doesn't know the game, but you can get the gist of what's happening there. Can anyone explain what's gone wrong?
Total Comments 15

Comments

Phylum's Avatar
And I just looked at it and realised what happened. The recursive call doesn't have the second argument, which wasn't required until less than 30 minutes ago.

I assumed this was down to my lack of Python knowledge rather than blindness.
Posted 01-04-2013 at 11:18 PM by Phylum

Varrok's Avatar
No problem.
Posted 01-04-2013 at 11:25 PM by Varrok

Nate's Avatar
If you've ever got a Python question, send me a PM. I wouldn't say I'm an expert, but I'm pretty good at it.
Posted 01-05-2013 at 12:45 AM by Nate

Phylum's Avatar
I don't know when I'm going to touch Python next, but I'll bare that in mind.

I actually want to write an AI to play Pentago, hence why I'm playing around with numbers like this. It turns out there are 8089461604168126540856524851928204740761088 different non-distinct ways in which a Pentago board can be filled including rotations of the quadrants. If I get everything up and running I might end up scripting it in Python, but I have a few other key things to tackle first, like figuring out how I'm going to search the array representing the board for patterns of 5 efficiently. This is the kind of thing that kills me, being self-taught.
Posted 01-05-2013 at 01:09 AM by Phylum

Nate's Avatar
That sort of problem is pretty normal for game AI. You'd want some sort of tree structure rather than an array, though.

I'd suggest checking out an introduction to AI book. Possibly one specific for games. If you wait until Monday I can tell you the one that I have at the office.


RE the title of this blog: Python is actually named after Monty Python, not the snake.
Posted 01-05-2013 at 02:41 AM by Nate

Phylum's Avatar
The only trouble with books is that they're expensive and I have no money. Especially not after the Steam Sales. I do need to get into trees at some point, but I can't see myself saving too many pennies for at least a year. I have lots on in the next few months and it's all costing me money.

I know about the Python naming, too. I went with snake for impact. Monty would have probably looked just as interesting, mind you.
Posted 01-05-2013 at 02:48 AM by Phylum

Nate's Avatar
I'll see what I can find with respect to free internet resources. Give me a few days.
Posted 01-05-2013 at 03:26 AM by Nate

Phylum's Avatar
This has led me to write a command line Pentago program, by the way. This is functional, but I have no doubt it is full of bugs. I would love for anyone with Java installed to give it a look. It will literally take a second to download.

There's no AI yet, but it's a working 2-player computer-sharing game. You can place pieces anywhere and the objective is to get 5 in a row. After you place a piece you must rotate one of the quadrants of the board, either clockwise or anti-clockwise.

It will ask how many human players you want, but it won't actually do anything with the input. It's still fussy about what you tell it, though. When you take a turn you have to give it two numbers with a space in the middle and no trailing space. Grid references start at 0. Quadrants work in the same way, but with a number and < or >. It's a bit odd at first, but it makes sense eventually.

The next step is to add the framework for an AI script. After than I have to actually write the AI. In other words, this is only the beginning.

Oh, and typing e, q or exit anywhere should quit. If it doesn't, take a screenshot and let me know.
Posted 01-05-2013 at 11:09 PM by Phylum
Updated 01-06-2013 at 12:27 AM by Phylum

MeechMunchie's Avatar
GREETINGS PROFESSOR PHYLUM

HOW ABOUT A NICE GAME OF CHESS
Posted 01-06-2013 at 04:27 AM by MeechMunchie

Varrok's Avatar
A strange game.
Posted 01-06-2013 at 04:39 AM by Varrok

Phylum's Avatar
I've implemented a system for running the AI from Python scripts.

IT LIVES!

This is all going together much smoother than I expected. I have a few things to tidy up on the Java end, then the struggle just comes into how I write the plug-in/plug-out Python scripts. At the moment all the computer does is play randomly, which can be a bit of fun but isn't really stimulating.
Posted 01-06-2013 at 05:52 PM by Phylum

Phylum's Avatar
I was having issues with Jython, so I'm hard-coding the AI in Java now

Play against the random-AI! There's also a readme now.
Posted 01-06-2013 at 09:44 PM by Phylum

Nate's Avatar
You may be interested in this. It's a free, online AI course. I'm guessing that only the first half of it will be relevant for you, but it has a lot about decision making and game theory.

I did it last year and it was really interesting.
Posted 01-07-2013 at 01:58 AM by Nate

Phylum's Avatar
Oh, thanks. I'll probably have to do that stat one first. We covered it in maths last year and I did exceptionally well on all of the stat questions in the exam, but I feel like there are still some gaps in my knowledge. Plus some of it looks like things we're covering this year in year 12 Studies.

I actually did exceptionally well on everything in my Maths Studies exam, scoring 115/118. I know two other people achieved the same mark, but I don't know that anyone beat that score.
Posted 01-07-2013 at 03:34 AM by Phylum

Nate's Avatar
You won't need stats for the AI course. There's a bit of probability, but (from memory) they give you all the background you need.
Posted 01-07-2013 at 04:14 AM by Nate

 

Recent Blog Entries by Phylum





 
 
- Oddworld Forums - -