Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > basic 2 player wordgame

Reply
Thread Tools

basic 2 player wordgame

 
 
Baba
Guest
Posts: n/a
 
      09-21-2010
Hi

I am working on a simple wordgame exercise: 2 players form a word by
alternating turns saying a letter, which is added on to the end of the
word fragment.

I am familiar with loops, iterations etc but i need a hint as to how
to approach alternating turns when writing this code?

exercise source:
http://ocw.mit.edu/courses/electrica...ents/pset5.pdf

thanks
Baba
 
Reply With Quote
 
 
 
 
Mel
Guest
Posts: n/a
 
      09-21-2010
Baba wrote:
> I am working on a simple wordgame exercise: 2 players form a word by
> alternating turns saying a letter, which is added on to the end of the
> word fragment.
>
> I am familiar with loops, iterations etc but i need a hint as to how
> to approach alternating turns when writing this code?


One way (not tested):

thisplayer = Player()
otherplayer = Player()
while not_won:
thisplayer.take_turn()
thisplayer, otherplayer = otherplayer, thisplayer



Mel.

 
Reply With Quote
 
 
 
 
bobicanprogram
Guest
Posts: n/a
 
      09-21-2010
On Sep 21, 6:25 am, Baba <raoul...@gmail.com> wrote:
> Hi
>
> I am working on a simple wordgame exercise: 2 players form a word by
> alternating turns saying a letter, which is added on to the end of the
> word fragment.
>
> I am familiar with loops, iterations etc but i need a hint as to how
> to approach alternating turns when writing this code?
>
> exercise source:http://ocw.mit.edu/courses/electrica...omputer-scienc...
>
> thanks
> Baba



Have a look at the SIMPL toolkit (http://www.icanprogram.com/06py/
lesson1/lesson1.html). This would allow your two players to be split
into two separate Python modules. It has the "advantage" that once
completed those two players could be deployed across a network,
likely without any code changes.

bob
 
Reply With Quote
 
Baba
Guest
Posts: n/a
 
      09-21-2010
On Sep 21, 1:39*pm, Mel <mwil...@the-wire.com> wrote:
> Baba wrote:
> > I am working on a simple wordgame exercise: 2 players form a word by
> > alternating turns saying a letter, which is added on to the end of the
> > word fragment.

>
> > I am familiar with loops, iterations etc but i need a hint as to how
> > to approach alternating turns when writing this code?

>
> One way (not tested):
>
> thisplayer = Player()
> otherplayer = Player()
> while not_won:
> * * thisplayer.take_turn()
> * * thisplayer, otherplayer = otherplayer, thisplayer
>
> * * * * Mel.



Hi Mel,

Thank you very much. Your suggestion works like a charm

def alternating_turns():
hand = []
thisPlayer = 'player1'
otherPlayer = 'player2'
while len(hand) < 3:
print 'turn %s: ' %(thisPlayer)
letter = raw_input('enter letter: ')
hand.append(letter)
thisPlayer, otherPlayer = otherPlayer, thisPlayer
print hand

alternating_turns()

thanks again! much appreciated. this was a first for me where i have
learned a practical way to apply mutation.

Baba
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TurboTax Basic vs. Taxcut Basic? Sharp Dressed Man Computer Support 1 01-12-2009 12:52 PM
What is the difference between Visual Basic.NET and Visual Basic 6? Jimmy Dean Computer Support 3 07-25-2005 07:05 AM
Re: Python interpreter in Basic or a Python-2-Basic translator. rrr@ronadam.com Python 0 05-02-2005 01:48 PM
Python interpreter in Basic or a Python-2-Basic translator. Engineer Python 6 05-01-2005 10:16 PM
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET Jaime MCSD 2 09-20-2003 05:16 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57