• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
K1NNY

A Monty Hall Paradox simulation program

7 posts in this topic

Today i created a simple program that simulates the Monty Hall paradox that i learned about here:

[url="http://betterexplained.com/articles/understanding-the-monty-hall-problem/"]http://betterexplained.com/articles/understanding-the-monty-hall-problem/[/url]

It took me about two class periods (about an hour and a half) and helped me teach myself about using and defining functions. It was a cool project and didn't take very long to get working. I'd like to hear feedback on how i did as i am still a beginner! Here's the code:

[source lang="python"]# Monty Hall paradox game #
import pygame
import random

#variables
doors = [1, 2, 3]
x = random.randint(1, 3)


#function
def show():
print '================='
print '|',doors[0],'| |', doors[1],'| |',doors[2],'|'
print '================='

def reveal():
if x == 1:
doors[0] = 'C'
doors[1] = 'G'
doors[2] = 'G'
show()
elif x == 2:
doors[0] = 'G'
doors[1] = 'C'
doors[2] = 'G'
show()
elif x == 3:
doors[0] = 'G'
doors[1] = 'G'
doors[2] = 'C'
show()

def switch():
y = str(raw_input("Would you like to switch doors?"))
if y == 'yes':
new_pick = int(raw_input('Which door?'))
user_door = new_pick
reveal()
elif y == 'no':
reveal()


show()
user_door = int(raw_input('Pick a door!'))

#logic
if user_door == 1 and x == 3 and x != 2:
doors[1] = 'G'
show()
switch()


elif user_door == 1 and x == 2 and x != 3:
doors[2] = 'G'
show()
switch()

elif user_door == 2 and x == 3 and x != 1:
doors[0] = 'G'
show()
switch()

elif user_door == 2 and x == 1 and x != 3:
doors[2] = 'G'
show()
switch()

elif user_door == 3 and x == 1 and x != 2:
doors[1] = 'G'
show()
switch()

elif user_door == 3 and x == 2 and x != 1:
doors[0] = 'G'
show()
switch()
[/source]
1

Share this post


Link to post
Share on other sites
At first glance, this seems the most unusual thing in your code:
[quote name='K1NNY' timestamp='1348766866' post='4984415']
if user_door == 1 and x == 3 and x != 2:
[/quote]

What does the "x != 2" part do? If x is 3, of course it is not 2, you don't need to check that.
0

Share this post


Link to post
Share on other sites
I read that as Monty [Python] Hall Paradox (silly me).

I am not familar with python but instead of doing
show() and switch() in each elif statement you could just do it at the end a single time.

Unless python doesn't allow you to do that, in which case ignore me =)
0

Share this post


Link to post
Share on other sites
Yes, of course python allows that, and the suggestion is sound.

Also, what do you want to happen if I pick the correct door to begin with? Your program seems to just end in that case.
1

Share this post


Link to post
Share on other sites
I would recommend you to make the door numbering to start from zero. This way, you are mixing door numbers (starting from 1) and array indexes (starting from 0). That makes your program very confusing. Alvaro is right, too.

Also, you should move the hard work of choosing the third door to the computer. Your "wall of elif" can be written like
[source lang="python"]
if (user_door == x)
#participant has chosen the right door, so you can choose either one unselected
#let's go with the first door as default and the second as fallback
#note that's not entirely correct, we should use the random function, but serves the purpose
#if you have the time, try to replace it to use the random function
if (x != 0)
goat_door = 1;
else
goat_door = 2;
else
#one door has car in there and another is selected, the presenter opens the third
#we iterate over the doors and find that one
for test_door in [1,2,3]
if user_door != test_door and car_door != test_door
#we mark the door
goat_door = test_door
#and since it's marked, we don't need to iterate over another one
break
#KLUDGE: Going from one-based numbering to zero-based by subtracting one
doors[goat_door-1] = 'G'
show()
switch()
[/source]
It probably does the same thing, but the readability is greatly improved. That reduces chance of making an error. And that will save your 2 hours of "why is this not working right" someday.[img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

P.S.: Use comments. Even a little bit really helps.
1

Share this post


Link to post
Share on other sites
I don't know Python at all; But I agree with ifthen:
[quote name='ifthen' timestamp='1348778100' post='4984487']
P.S.: Use comments. Even a little bit really helps.
[/quote]

As a beginner: I comment to the point that I feel like I'm over-commenting; but I'm not. I can't count how many times I had to revisit a code file a week or month down the road and had to sit and stare at it wondering what the cob I was thinking when I wrote it. At the time, I probably thought it was a brilliant execution. But it isn't anymore. And my error is probably somewhere in those lines. Things would be a lot easier if I knew what I was thinking at 0300hrs that morning when I typed it... :/

So comment and comment some more. And [b]Be descriptive.[/b]

-Shadow
0

Share this post


Link to post
Share on other sites
[quote name='ShadowValence' timestamp='1348785725' post='4984517']
As a beginner: I comment to the point that I feel like I'm over-commenting; but I'm not. I can't count how many times I had to revisit a code file a week or month down the road and had to sit and stare at it wondering what the cob I was thinking when I wrote it. At the time, I probably thought it was a brilliant execution. But it isn't anymore. And my error is probably somewhere in those lines. Things would be a lot easier if I knew what I was thinking at 0300hrs that morning when I typed it... :/
[/quote]
I comment almost every single line in my code, and then filter out useless stuff later. I find it works well. I just don't get the hero coder attitude where people would write cryptic uncommented code that "just works". If you don't understand your own code, you probably should try to.
0

Share this post


Link to post
Share on other sites
[quote name='Bacterius' timestamp='1348786089' post='4984521']
ero coder attitude
[/quote]

HAHA! I had no idea that it had a name! :D
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0