Welcome!

Welcome one and all exclusively to Musings on Tap! Our doctrine is that all thought is free thought (we even share tea;)). Download at your leisure and be comforted that ideas will never die. The purpose is to incite thought and revolutionize ideas. We, the authors, yet never finishers, share different perspectives on life and so this blog will indeed be two-dimensional. Topics will be humorous and perhaps quite silly. Topics will be serious and perhaps quite morbid. Sentences will even contain unparalleled parallel structure. Oh and we cater:).

Saturday, October 12, 2013

Russian Roulette

I am not even going to pretend I'm good at programming. However,  I will say that this project was fun to put together. I think VBS or Visual Basic Script is one of the easiest if not easiest programming languages to learn, so I made a program that simulates Russian Roulette. You enter how many players you want to play and then put in their names. The program will then randomly generate a number that will decide if the next person is dead or not. After it goes through every bullet (more guns/bullets) if playing with more than 6 people it will tell you if they died or not. At the end, it prints out all the survivors and all the dead. It was cool experimenting around with arrays and for loops, because it saves a lot of time and when it all works you feel like a wizard. Like I said I'm a novice.

There are some flaws in the program. For example, if you are playing with n>6 people the program plays as if it has a Ceiling(n/6)*6 chambered gun instead of Ceiling(n/6) 6 chambered guns. This slight variation might make a difference because the chances can be greater than or less than 1/6 (most importantly greater than) for a random distribution along the line. We can talk to Putin about how Russian Roulette works with n>6 people. Also, the way the code is setup is the player dies if the randomly generated number is < than n+1 bullets. And I had to make the number of chambers remaining go down accordingly. So, in a large n case we are able to see a uniform distribution of people dying. I am not sure why it doesn't print out all the names; perhaps there is a character limit. Here's to version 2.0!

'############################RUSSIAN ROULETTE##################################
msgbox "Welcome to Russian Roulette, the game of your life!"
count = inputbox("How many players?")

Function Ceil(x)
    If Round(x) = x Then
        Ceil = x
    Else
        Ceil = Round(x + 0.5)
    End If
End Function
'thank you random internet post for this ceiling function ^^

bullets = Cstr(ceil(count/6))
chambers=(ceil(count/6))*6
msgbox "You will be playing with "+ Cstr(ceil(count/6)) +" standard 6 chamber revolver(s)"
guns = ceil(count/6)
dim player()

for i = 1 to count
ReDim Preserve player(i)
player(Cstr(i))= inputbox("Please enter " + "Player "+ Cstr(i)+"'s name")
if player(Cstr(i))="" then
player(Cstr(i))="Player "+Cstr(i)
end if
if count > 1002 then
msgbox "This will surely be too tedious, Shirley."
i = count
count = 0
end if
aglom = aglom + player(i) + ", "
next

msgbox aglom + " this is it. This is Russian Roulette. Dun Dun Dunnnnn!"
Randomize()


for i = 1 to count
newchambers= chambers-(i-1)
'pickgun = CInt(Int((guns * Rnd()) + 1))
pick = CInt(Int((newchambers * Rnd()) + 1))
'msgbox Cstr(pick)+" bullets"+Cstr(bullets)
if pick < bullets+1 then
msgbox player(i)+ " is dead. BANG!"
aglommm=aglommm+" "+ player(i)+" "
bullets=bullets-1
if bullets= 0 then
for k = (i+1) to count
leftover= leftover +player(k)+" "
next
end if
else
msgbox "Click! "+ player(i)+" lives"
aglomm= aglomm+ player(i) + " "
end if
if bullets= 0 then
i=count
end if
next

msgbox "game over, congratulations to the survivors: " + aglomm + leftover
if aglommm <> "" then
msgbox "And" + aglommm+", not feeling so Russian, huh?"
end if

'###########################RUSSIAN ROULETTE###################################

To play this super fun violent game, just copy the above code into a notepad. Windows only, sorry. Then save the file as RussianRoulette.vbs. Or just make sure the file extension is .vbs
Next change "Save As Type" in the drop down to "All files"
Leave encoding as "ANSI"

Now find the file you saved and double click on it and it should run!

In the DeMi test trial, I unfortunately died. It was but a flesh-wound as I am all better now.


Cheers,

Mi!

2 comments:

  1. Visual Basic easiest? I know a bit of Pyhon, and found that pretty easy to learn. I haven't tried VB really though.

    ReplyDelete
  2. Oh yeah, Python's pretty easy too. And I think that may be the easiest of the full-fledged languages. There is a lot you can't do, or you really wouldn't want to do in VB. It's easy because you don't have to declare variables or set their type. There is even less random syntax you must know like parentheses and semicolons. So I would say to give it a try!

    ReplyDelete

Please! It's quite bare down here!

Followers