DPChallenge: A Digital Photography Contest You are not logged in. (log in or register
 

DPChallenge Forums >> General Discussion >> Anybody a programmer?
Pages:  
Showing posts 1 - 25 of 51, (reverse)
AuthorThread
02/28/2009 09:22:56 PM · #1
I am witting Pseudocode for a Tic-Tac-Toe game where the computer must always win and cannot cheat. Here is what I think the answer should be.

(keep in mind that this is super low level because we are all programming noobs in this class)

Start
Computer Place X in Center Square
Computer Place o is right bottom square
Computer place X in top center square
Computer place o in right center square
Computer place x in bottom center square
display "I always win"
End
02/28/2009 09:31:10 PM · #2
If the computer is playing both sides, the computer will always win. :)

Why would the "O" not block the move by going bottom center on his second turn?
02/28/2009 10:06:37 PM · #3
That is what I thought, computer will win if he is playing both sides. He doesn't block because I want the computer to win...

I don't know. It is a stupid assignment.
02/28/2009 10:12:17 PM · #4
I could tell you the answer, but that would be cheating. :)

02/28/2009 10:17:57 PM · #5
I get the impression that you are supposed to develop an algorithm which ensures that for any move made by player A, the player B finds a move which would not prevent the player A from winning. But then again, that might be a rather difficult problem for a beginner.
02/28/2009 10:29:26 PM · #6
I would think there should be some healthy conditional statements and when all is said and done three arrays will come in handy. Good luck - let us know how you end up! :-)
02/28/2009 10:42:44 PM · #7
I once had to write a 4-in-a-row style program in an obscure language as an assignment (WAY back then).

I found the best way to do it was to pick a random starting position, then think about how you would oppose that play. Follow that by breaking your strategy down into logical steps and then it becomes fairly easy to put it into a psuedocode, which in turn will make it easy to actually write.

Good luck, these things always end up taking 10 times longer than you expect when you start!
02/28/2009 10:45:02 PM · #8
I am going to fail...My mind just doesn't work this way. I have spent 2 hours trying to get a VB program to calculate interest.

At least I figured it out finally...Seems like it would be easy.

Message edited by author 2009-02-28 22:46:44.
03/01/2009 12:02:11 AM · #9
Ok, so I was working on this for my first program. I had to make a Interest Calculator deal. Pretty simple thing.

Can anybody help me figure out how to format the textboxes to currency and percent. For instance when they tab out of a textbox I want it to automatically add the $ and .00 to the end of the amount. And when they enter say 5 for the percent I want the box to read 5% when they tab to the next box.

Here are the VB Files if anybody wants to show me how smart they are.

And just for those who might think I am cheating, I am not. This already meets the requirements for the project I am just trying to go above and beyond so I get to graduate with honors on May 9th.
03/01/2009 12:05:28 AM · #10
It's been awhile since VB...plus I'm at the wrong PC (have Visual Studio on laptop).

What have you tried so far? Isn't there a "lost focus" event for the text field?
03/01/2009 12:09:16 AM · #11
Keep in mind that I have been at this programming thing for a couple hours now. So I don't know anything at all.

I have not added any events to the text field. Only the TxtChange event exists currently for that field that I am aware of.

Here is my code:

Private Sub Compute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Compute.Click
Dim Principal As Decimal, Rate, Years, sum As Double
Principal = CDbl(txtPrincipal.Text)
Rate = CDbl(txtRate.Text / 100)
Years = CDbl(txtTime.Text)
sum = (Math.Round((1 + Rate) ^ Years * Principal, 2))
txtOutput.Text = "When $" & CStr(Principal) & " is invested for " & CStr(Years) & " years at " & CStr(Rate * 100) & "% interest " & " the balance is $" & CStr(sum)
End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Private Sub txtPrincipal_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPrincipal.TextChanged

End Sub
End Class
03/01/2009 12:21:13 AM · #12
I don't understand why you don't just go into the textbox properties and changed the Format of the text box to Currency with a decimal place of 2, and change the other to Percent format. Maybe I'm missing the point?
03/01/2009 12:31:04 AM · #13
Originally posted by MWitt:

I don't understand why you don't just go into the textbox properties and changed the Format of the text box to Currency with a decimal place of 2, and change the other to Percent format. Maybe I'm missing the point?


You might not be missing the point, I am a programming idiot and didn't know that I could do that. lol
03/01/2009 12:37:48 AM · #14
Originally posted by Jason_Cross:

Originally posted by MWitt:

I don't understand why you don't just go into the textbox properties and changed the Format of the text box to Currency with a decimal place of 2, and change the other to Percent format. Maybe I'm missing the point?


You might not be missing the point, I am a programming idiot and didn't know that I could do that. lol


Well, I thought maybe you had to do it programatically! You actually have a lot of control over format in the properties! Check it out. :)
03/01/2009 01:05:13 PM · #15
Naughts and Crosses is one of those classic no win games.... It is lost not won - meaning a player has to lose as there is nothing the other player can do to force a win without a mistake from the opponent.
03/01/2009 01:35:43 PM · #16
Originally posted by Jason_Cross:

Keep in mind that I have been at this programming thing for a couple hours now. So I don't know anything at all.

I have not added any events to the text field. Only the TxtChange event exists currently for that field that I am aware of.

Here is my code:

Private Sub Compute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Compute.Click
Dim Principal As Decimal, Rate, Years, sum As Double
Principal = CDbl(txtPrincipal.Text)
Rate = CDbl(txtRate.Text / 100)
Years = CDbl(txtTime.Text)
sum = (Math.Round((1 + Rate) ^ Years * Principal, 2))
txtOutput.Text = "When $" & CStr(Principal) & " is invested for " & CStr(Years) & " years at " & CStr(Rate * 100) & "% interest " & " the balance is $" & CStr(sum)
End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

End Sub

Private Sub txtPrincipal_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPrincipal.TextChanged

End Sub
End Class


There is a vb function (fv) that will do everything you are looking for. It is intended to handle monthly payments, but by setting the present value to your starting amount and making payments of zero, you will get the proper answer, formatted to 2 decimal points. Just remember to take the absolute value of the result. The big advantage here is that it handles compounding if you are applying interest monthly.

Message edited by author 2009-03-01 13:36:17.
03/02/2009 12:52:38 PM · #17
Wikipedia has a nice entry on tic-tac-toe. Check out the "Strategy" section. The 8 steps it lists to play perfectly would be a good starting point for developing the pseudo-code.
03/02/2009 12:58:40 PM · #18
I am really not a good programmer. It confuses my logic circuits.
03/02/2009 01:07:33 PM · #19
this story will not be useful to you but it might make you smile.

Years ago I had a Commodore 64, and I used to always go and buy a magazine called "Compute's Gazzette" for Commodore owners. In the back they always had programs in basic and machine code that you could type in. So one night (i was about 13 at the time) I decided to type a game in and stayed up til 4 in the morning to do it all at once. after i finally went to sleep, the only thing i dreamed all night was that i would type in a line of code and when i would hit enter, it would erase itself, over and over again until i woke up.....it was after that dream i knew i would never be a programmer.....
03/02/2009 01:12:44 PM · #20
My code is so sloppy. My teacher uses words like "your doing good" and "this was a good try" and "you will get the hang of it" in the e-mails to me. So obviously I am a goof at programing.
03/02/2009 09:09:36 PM · #21
It has been three days and I cannot find this magic "formatcurrency" deal in VB. I am super stuck.
03/02/2009 09:26:08 PM · #22
I don't use VB so can't help you there.......
I had problems in Programming at Uni as I learnt to program in Pascal, and at Uni class they were using C. They are so similar that you forget the difference, and the tutor just kept correcting my placement of the ';'.

I now have programmed in Java, Matlab, pascal, Basic (briefly, but not VB), C and Fortran............If I try and program now, I just get confused between all of them, so I give up..............

Try spending a week at work sorting through pages of code and debugging as the wrong answer is being produced, and it is because one equation is accidentally outside one of the for loops, rather than inside it...........there were hundreds of for loops in there...............

I no longer program, I find it better for my sanity................
03/02/2009 09:53:20 PM · #23
umm. You can't always win. The best possible strategy is either win or draw. Either your teacher meant program the best possible strategy, or he set you a fairly pointless assignment in drawing crosses on a board in a specific order.

Which may not be entirely pointless in real code (you'd learn some mechanics), but it is in pseudocode.
03/02/2009 10:14:04 PM · #24
I think that I should buy that Pentax and travel the world taking photos of the beautiful people. And leave the programing to somebody else. I hate traveling though, so that probably would not work either. I am pretty much screwed.
03/02/2009 10:17:50 PM · #25
Originally posted by Jason_Cross:

It has been three days and I cannot find this magic "formatcurrency" deal in VB. I am super stuck.


It appears after doing some research on this that things have changed a bit since VB Studio 6!

If you have a datagrid with databinding to textboxes you can use the following:

In the properties for the textbox, expand the databindings property and select the Advanced property then click the ... elipse button. In the resulting dialog, you can enter the format.

It looks as though all of this is done with code these days and I have fallen behind the times! LOL
Seems like a lot of work to write code to change the textbox format. I'd prefer to create the textbox with the formatting of choice while designing and not at runtime.

Sorry if I wasted your time.
Pages:  
Current Server Time: 04/16/2024 02:41:38 PM

Please log in or register to post to the forums.


Home - Challenges - Community - League - Photos - Cameras - Lenses - Learn - Prints! - Help - Terms of Use - Privacy - Top ^
DPChallenge, and website content and design, Copyright © 2001-2024 Challenging Technologies, LLC.
All digital photo copyrights belong to the photographers and may not be used without permission.
Current Server Time: 04/16/2024 02:41:38 PM EDT.