8000 GitHub - dabent/pyfour: Connect
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

dabent/pyfour

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Here are some notes on my thinking process when building the Connect Four game.

For the first version I'm using the default 7x6 board as shown in Wikipedia: http://en.wikipedia.org/wiki/Connect_Four 

I'm taking an incremental approach to this, beginning with the minimum viable game, then looking to add features as I go along/

I'm starting with the model of the board, and then the computer player's decision engine and state machine to drive the game. I'll build unit tests for each piece to I can be sure the pieces work once they are brought together.  Once the basic engine is running, I'll build a better engine for extra credit.  The initial version will be held in memory.

If I really get on a roll, I can put the board model and game state in a database so someone can play the computer in a Django app.  I'll already have the logic to play the game in place, and could even potentially set up a site with user accounts where people could  play any two-player board game against each other, swapping out the model and game engine for other games.

But I'm getting ahead of myself.  Time to design and code!
 
UPDATE:

OK, I'm turning in what I've got so far.  I've developed the basic command-line program in Python that plays Connect Four interactively.  It has a standard computer opponent should block a human from winning when able to and a more advanced opponent that goes for the win, and tries to avoid setting up an opponent for an easy win.  The advanced opponent needs more work, but I thought I'd show you the design of what I've got.

I use a "board" class hierarchy to model the game board itself with tests to make sure I've got all the basic board moves right.  Then I developed a strategy hierarchy to support different levels of game play.  Adding another 2-player board game (like Tic-Tac-Toe) would use polymorphism for the board and strategy classes, and higher levels of opponents are added with inheritance.

I developed unit tests for the classes as well.  Given time, I'd adopt a much more detailed test strategy and add more unit tests, but I wanted you to see what I've got.  I'm open to feedback.

I also could tie this to a Django model using and adapter to map the board classes to database entries.

Here are the files:

board.py - the board classes.
game.py - the game engine
strategy.py - the comptuer opponent's brains
testBoard.py - board tests
testStrategy.py - strategy tests

Here's how to play:

python game.py

That gives you the first move and an easy computer opponent.  The -c flag lets the computer go first and the -h flag gives a harder opponent, so:

python game.py -ch 

Lets a harder computer opponent go first.

Let me know what you think...

About

Connect

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0