Aces High Bulletin Board
General Forums => The O' Club => Topic started by: SilverZ06 on April 01, 2014, 04:42:53 PM
-
I am taking an intro to visual basic using visual studio 2012 and I have a horrible instructor. He basically reads power point slides to us and that is it. No hands on work in the class room at all. I don't understand how you have a computer programming class without doing any work on computers :headscratch:. Anyway I have a problem that is due tonight but I have until next tuesday to turn it in late. Here is the problem:
(http://i1298.photobucket.com/albums/ag49/PewterC5/pokerhand_zps717e87cc.jpg) (http://s1298.photobucket.com/user/PewterC5/media/pokerhand_zps717e87cc.jpg.html)
I am seriously lost as to how I am supposed to populate the array with input from text boxes. How do I determine what the user entered and where it goes? For example. Lets say a user entered a 5 of clubs. How does the program know to populate a 1 in the array "hand" in element (0,4)? I do not see any similar examples in the book or power point slides that explains this. Hopefully someone here has some knowledge they would like to share with me. Thanks in advance.
-
The instructions suck. He wants you to put a 1 or 0 in the 2d array based on the user input . I would tAke A string like h11 as input the set 3,11to 1. Next you need to run test on the 2d array for flush straight 2pair ext
-
Tip do searches starting with hi hand first ,does you will get4kind showing as pair type problems
-
PS this is not a tiny program would be 1 to3 Hours to me
-
If this is a basic Visual Basic course, are you sure he expects you to open a text box?
I ask because I don't see that in these instructions and most of the time these guys are looking for text based I/O.
I'm really rusty, ie I don't remember the reserve words anymore, and the language has been updated since the '80s ...
start: REM re-entry point
PRINT "Enter first card:"
INPUT FirstCard$
PRINT "Enter second card:"
INPUT SecondCard$
etc
CALLSUB Transfer_to_array
etc
...
GOTO start
Transfer_to_array
code
END SUB
-
52 IF statements! :aok
-
52 IF statements! :aok
:lol That is what I was trying to avoid
If this is a basic Visual Basic course, are you sure he expects you to open a text box?
I ask because I don't see that in these instructions and most of the time these guys are looking for text based I/O.
I'm really rusty, ie I don't remember the reserve words anymore, and the language has been updated since the '80s ...
start: REM re-entry point
PRINT "Enter first card:"
INPUT FirstCard$
PRINT "Enter second card:"
INPUT SecondCard$
etc
CALLSUB Transfer_to_array
etc
...
GOTO start
Transfer_to_array
code
END SUB
This is what the example in the book showed:
(http://i1298.photobucket.com/albums/ag49/PewterC5/20140401_233237_zpsz7cicjce.jpg) (http://s1298.photobucket.com/user/PewterC5/media/20140401_233237_zpsz7cicjce.jpg.html)
Apparently everyone in the class is having trouble with this program so he extended the due date 1 week without penalty. I told my instructor I was having trouble figuring out how to populate the array and asked how to do it and this was his most helpful answer..."There are many ways to do it.....People do it differently." :bhead
-
Do you get extra credit for error trapping it against the user from inputting the same value twice?
-
Do you get extra credit for error trapping it against the user from inputting the same value twice?
I don't think so. I don't think he even checks that to be honest. I think he enters a hand and just sees if the program works. If this were my "C" programming instructor I would definitely be losing points for not validating data, but this guy isn't that thorough. I wish I would have looked this instructor up before signing up for his class. I really want to learn this but just having him reading power point slides without any hands on training is not an easy way for me to learn.
-
I haven't programmed since high school but I would first populate a 4x13 array with 1 (ace) through 13 (K) in each row.... for example 2 of spades will be (1,2) 2 of hearts (2,2) etc
Then on user input, convert a jack to ace input and suit to its corresponding number. you now have an x and y variable that you need to cross check to the array. Now retrieve (x,y) so say he enters 2 S it will pull (1,2). With these 5 array locarions put 1 into a 4x13 new array with 0s in all others fields. Maybe that gets you in the right direction? :headscratch:
Hitech I know what you are thinking and the answer is no I can't work for you I am already happily employed.
-
Wait, is this another April Fools joke?
argh, Edit for correction.
Why would you DIM 3,12 when all you'd need is DIM 4,1? Zero the two values for a no card place holder.
ie
if card 2 is a 5 of spades, then 2,0 = 5 and 2,1 = spade
if card 3 hasn't been input, then 3,0 = 0 and 3,1 = 0
etc
The reverse is also acceptable, DIM 1,4 and matches the suit before the value in the original exercise. Both are 10 element arrays.
Comparisons are much more straight forward.
-
DIM 4,13
A|2|3|4|5|6|7|8|9|J|Q|K| [Total in Suit]
0|0|0|0|1|0|0|0|0|0|0|0| [1]
0|0|0|0|1|0|0|0|0|0|0|0| [1]
1|0|0|0|1|0|0|0|0|0|0|0| [2]
1|0|0|0|0|0|0|0|0|0|0|0| [1]
Total count of same value cards
2|0|0|0|3|0|0|0|0|0|0|0|
Three 5's over Two Aces: Full House
-
Create a userform with 2 rows of drop down boxes that are pre-validated to suits / cards.
You can refer to the text value of an input box on a userform as if it was a declared variable and, therefore, run scripts to decide where in the array needs to be a 1.
eg, assuming you've already discovered the suit and assigned a numerical value to it.....
If VAL(userform1.textbox1.text) > 0 then 'ie, if the text entry has a numerical value then it must be 2 - 10.
array(suit, VAL(userform1.textbox1.text)-1) = 1
End If
Then you've gotta do the same for cards without a numerical value....however, you could use the ASCII value if you want to avoid lots of IF whatever = "K", etc.
-
Create a userform with 2 rows of drop down boxes that are pre-validated to suits / cards.
You can refer to the text value of an input box on a userform as if it was a declared variable and, therefore, run scripts to decide where in the array needs to be a 1.
eg, assuming you've already discovered the suit and assigned a numerical value to it.....
If VAL(userform1.textbox1.text) > 0 then 'ie, if the text entry has a numerical value then it must be 2 - 10.
array(suit, VAL(userform1.textbox1.text)-1) = 1
End If
Then you've gotta do the same for cards without a numerical value....however, you could use the ASCII value if you want to avoid lots of IF whatever = "K", etc.
I was going to use 1 for Ace, 11 for jack, 12 for queen, and 13 for king. So that would still work. But how would I then test against the suit? I guess I need to make two single dimension arrays and then combine them to create the two dimensional array?
-
Wait, is this another April Fools joke?
argh, Edit for correction.
Why would you DIM 3,12 when all you'd need is DIM 4,1? Zero the two values for a no card place holder.
ie
if card 2 is a 5 of spades, then 2,0 = 5 and 2,1 = spade
if card 3 hasn't been input, then 3,0 = 0 and 3,1 = 0
etc
The reverse is also acceptable, DIM 1,4 and matches the suit before the value in the original exercise. Both are 10 element arrays.
Comparisons are much more straight forward.
The way I understand it in VB is a Dim array(3) is actually a 4 element array 0,1,2,3. I don't know why VB does it this way when I was taught in logic and so far in "C" that the array size is determined by the number of elements. so in "C" an array[3] would actually only contain three elements 0,1,2.
-
Im Not sure of exact VB syntacs it has been a long time but the idea is this
int dim(4,13) Cards;
int HandIs4OfAKind(int dim(4,13)Cards)
{
int Suite,Number;
for Number = 1 to 13
if(Cards[1][Number] = 1 and Cards[2][Number] = 1 and Cards[3][Number] = 1 and Cards[4][Number] = 1)
return 1
return 0
}
-
aisdbvlqejfnbvjqkenrv 4[32452345] 12nsk.//123
hope this helps. :salute
-
Not that I like doing other people's homework, but I'm a bit bored at work today. ;)
This snippet of code it attached to the Click event of a button, and for testing I coded the test to simulate someone entering Ace of Diamonds:
Dim arrayCards(3, 12) As Integer
Dim Suit As String
Dim Face As String
'Pre-populate array with all zeros
For s = 0 To 3
For f = 0 To 12
arrayCards(s, f) = 0
Next
Next
'Simulate values from form textbox
Suit = "D"
Face = "1"
'Set the corresponding array value to 1
Select Case Suit
Case "C"
arrayCards(0, Face - 1) = 1
Case "D"
arrayCards(1, Face - 1) = 1
Case "H"
arrayCards(2, Face - 1) = 1
Case "S"
arrayCards(3, Face - 1) = 1
End Select
This should result in your two-dimensional array filled with zeros except for the element for the Ace of Diamonds. You should be able to use this as a template for gathering all the values from all the textboxes on your form (based on the picture of the form in your previous post).
Enjoy.
-
Im Not sure of exact VB syntacs it has been a long time but the idea is this
int dim(4,13) Cards;
int HandIs4OfAKind(int dim(4,13)Cards)
{
int Suite,Number;
for Number = 1 to 13
if(Cards[1][Number] = 1 and Cards[2][Number] = 1 and Cards[3][Number] = 1 and Cards[4][Number] = 1)
return 1
return 0
}
Thank you Hitech! This will definitely help.
-
Man with all you guys talking gibbirish makes me want to learn it to. What do I need to get and go to learn coding. I think it might be come a new hobby when I am bored of flying.
-
Not that I like doing other people's homework, but I'm a bit bored at work today. ;)
This snippet of code it attached to the Click event of a button, and for testing I coded the test to simulate someone entering Ace of Diamonds:
Dim arrayCards(3, 12) As Integer
Dim Suit As String
Dim Face As String
'Pre-populate array with all zeros 'I believe in VB when you declare an array the elements are automatically initialized to 0 (unless initialized to something else obviously).
For s = 0 To 3
For f = 0 To 12
arrayCards(s, f) = 0
Next
Next
'Simulate values from form textbox
Suit = "D" 'So this is where I am lost. would this be something like: Select Case suit txtCard1Suit.text
Face = "1" Case "C"
arrayCards(0,Face-1)=1
'Set the corresponding array value to 1
Select Case Suit
Case "C"
arrayCards(0, Face - 1) = 1
Case "D"
arrayCards(1, Face - 1) = 1
Case "H"
arrayCards(2, Face - 1) = 1
Case "S"
arrayCards(3, Face - 1) = 1
End Select
This should result in your two-dimensional array filled with zeros except for the element for the Ace of Diamonds. You should be able to use this as a template for gathering all the values from all the textboxes on your form (based on the picture of the form in your previous post).
Enjoy.
Then I would use a For loop for all cards to do the same to populate the array. Thank you so much. This helps tremendously I still have a lot to figure out but this gets me going instead of blankly staring at my screen.
-
Ok, lesson #2 :D
Build your form and name your textboxes something like "txtCard1", "txtCard2", "txtSuit1", "txtSuit2", etc. and use the Tag property to set the card textboxes to "card". This way, you can loop through all controls and only work with specific textboxes without having to spell out each name. From there, it's just the one loop, each suit textbox name is created to match the card box you're working with, and your array is complete and ready for you to figure out what poker hand it is.
Dim arrayCards(3, 12) As Byte
Dim Suit As String
Dim Face As String
Dim idx As Byte
Dim Suitbox As String
'Loop through all controls on the form
For Each ctl As Control In Me.Controls
'only grab controls tagged with "card"
If ctl.Tag = "card" Then
'get control number (right-most character) from the textbox name so you can get corresponding suit
idx = ctl.Name.Substring(Len(ctl.Name) - 1)
Suitbox = "txtSuit" & idx
'get the values in the text boxes
Suit = Me.Controls(Suitbox).Text
Face = ctl.Text
'Set the corresponding array value to 1
Select Case UCase(Suit)
Case "C"
arrayCards(0, Face - 1) = 1
Case "D"
arrayCards(1, Face - 1) = 1
Case "H"
arrayCards(2, Face - 1) = 1
Case "S"
arrayCards(3, Face - 1) = 1
End Select
End If
Next ctl
-
I'm curious,do VB array indices start with 0 or 1? If my memory is correct they used to start at 1.
They may have simply changed to it be backwards compatible that dim statement allocates one more then entered so you don't overflow with one based, but can then index from 0 base.
Hence why the example Dim(3,12) would work if zero based is now supported in VB.
I't has been over 20 years since I wrote any VB.
HiTech
-
Man with all you guys talking gibbirish makes me want to learn it to. What do I need to get and go to learn coding. I think it might be come a new hobby when I am bored of flying.
Not a bad place to start....and it's free.
http://www.codecademy.com/ (http://www.codecademy.com/)
-
Yep, VB uses base 0 for arrays. For VBA (Visual Basic for Applications) for automating Excel, Access, etc. you can use the statement "Option Base 1" in the code to specify arrays should should at 1 instead of 0.
In Microsoft Visual Basic 6.0, you can define arrays with the lower bounds and upper bounds set to any integer. You can also use the ReDim statement to reassign a variant as an array.
In Visual Basic .NET, the lower bound for arrays is set to zero to enable interoperability with other languages. Furthermore, you cannot use ReDim unless the variable was previously declared with Dim As Array. The Option Base {0|1} has been removed in Visual Basic .NET because it is no longer required. Although this restricts how you define arrays, it enables you to pass arrays between Visual Basic .NET and any other language in the Microsoft .NET Framework.
-
I recall that c++ arrays start at 0 now that you mention it.
-
I recall that c++ arrays start at 0 now that you mention it.
I think that's correct as well....but its been a LOOONG time since doing anything in C++ for me.
I am old and befuddled now, 20 years of IT down the crapper. Pretty soon I'll be old and distrustful of technology like my father. Heck...I don't even get the point of Twitter! ;)
-
PS this is not a tiny program would be 1 to3 Hours to me
Yea. I could brute force it with conditionals because I don't have any poker-related pattern recognition shortcuts in my brain. One trick could be to add up all the columns and rows individually. A row that equals 5 is a flush. 5 consecutive columns (including wrap-around to account for ace) that equal 1 is a straight. edit - I see that's already been posted by someone else. In any case, I'd probably start off brute force condition checking for each type of hand, and then look for patterns so I could combine the tests as much as possible. There's probably at least one test where recursion could result in some tight code, at the expense of readability and boundary checking and wasted time sorting out the logic and exit conditions.
VB had just come out when I went through my comp sci degree program and my school didn't offer any courses in it. I think they looked at it as a fad and wanted to see if it gained any traction. Too bad. Instead of learning VB I got ADA, massively parallel programming, and a handful of other courses that would have been of value if I'd continued my USAF career in the R&D field, but of very little value now. I guess the parallel programming theory would apply to low level graphics hardware programming, but I don't think most developers dive that deep even with modern GPUs. The largest computer I had time on was a govt supercomputer and I had access to a 100x100 2D array of independently programmable processors for about a total of 1 hr of compute time. The architecture had both shared and isolated memory, and each processing node had a very low latency shared memory register with cross-connected adjacent nodes. I think I used a total of 200 seconds of compute time and never did any optional projects that could have really stretched that computer's capabilities. Back in 1993...
-
For VBA you can use the statement "Option Base 1" in the code to specify arrays should should at 1 instead of 0.
I've learned something today. :)
-
Ok, lesson #2 :D
Build your form and name your textboxes something like "txtCard1", "txtCard2", "txtSuit1", "txtSuit2", etc. and use the Tag property to set the card textboxes to "card". This way, you can loop through all controls and only work with specific textboxes without having to spell out each name. From there, it's just the one loop, each suit textbox name is created to match the card box you're working with, and your array is complete and ready for you to figure out what poker hand it is.
Dim arrayCards(3, 12) As Byte
Dim Suit As String
Dim Face As String
Dim idx As Byte
Dim Suitbox As String
'Loop through all controls on the form
For Each ctl As Control In Me.Controls
'only grab controls tagged with "card"
If ctl.Tag = "card" Then
'get control number (right-most character) from the textbox name so you can get corresponding suit
idx = ctl.Name.Substring(Len(ctl.Name) - 1)
Suitbox = "txtSuit" & idx
'get the values in the text boxes
Suit = Me.Controls(Suitbox).Text
Face = ctl.Text
'Set the corresponding array value to 1
Select Case UCase(Suit)
Case "C"
arrayCards(0, Face - 1) = 1
Case "D"
arrayCards(1, Face - 1) = 1
Case "H"
arrayCards(2, Face - 1) = 1
Case "S"
arrayCards(3, Face - 1) = 1
End Select
End If
Next ctl
This looks great but it is definitely way more advanced than we have gotten so far in this class. I am going to get working on this code tonight or tomorrow night and I'll post what I can come up to get you guys' input/advise. I really do appreciate all of you guys' help. I bet I will learn more in this thread than in this class.
-
This looks great but it is definitely way more advanced than we have gotten so far in this class. I am going to get working on this code tonight or tomorrow night and I'll post what I can come up to get you guys' input/advise. I really do appreciate all of you guys' help. I bet I will learn more in this thread than in this class.
Yeah, I'm a big fan of using the form to allow me to do less coding work. :old:
If you need more explanation of how and why my last code chunk does what it does, let me know.
I feel your pain about the class...many "teachers" either barely know the subject or just don't know how to transfer their knowledge.
Good luck with the project!
:salute
-
OK, I finally got a chance to sit down tonight and work on this. I will be working on it all day tomorrow as well. Since I am fairly new at this I like to see everything that is happening so my code to populate my array is very redundant. I have added an "Enter Card" button to all five cards so that each button click populates a segment of the array. This is not exactly end-user friendly at the moment but it helps me to visualize what is going on. Here is my form and my code so far. I am only including the code for the first button click as the remaining 4 are identical except for changing out the numbers of the buttons.
FORM:
(http://i1298.photobucket.com/albums/ag49/PewterC5/form_zps3c63e641.jpg)
Option Strict On
Option Explicit On
Option Infer On
Public Class Form1
Dim hand(3, 12) As Integer
Private Sub btnCard1_Click(sender As Object, e As EventArgs) Handles btnCard1.Click
Dim suit As String
Dim faceValue As Integer
suit = txtCard1Suit.Text.ToUpper
faceValue = CInt(mtbCard1.Text) - 1
If (faceValue < 1) Or (faceValue > 13) Then
MessageBox.Show("Invalid Denomination for Card 1. Please re-enter the denomination.", "ERROR")
End if
Select Case suit
Case "C"
hand(0, faceValue) = 1
Case "D"
hand(1, faceValue) = 1
Case "H"
hand(2, faceValue) = 1
Case "S"
hand(3, faceValue) = 1
Case Else
MessageBox.Show("Invalid value for card 1 suit. Please re-enter the suit.", "ERROR")
End Select
End Sub
So now I believe I have the array correctly populated. Now I need to figure out how to make functions and pass the array to them to check against a hand. Does anyone see anything wrong with my code so far or have any suggestions for improvement? Thanks for all you guys' help again :salute :cheers:
-
After reading this thread Lawndarts brain hurt,,,,, uggg I finally realized I'm a dummy when it comes to internal but when it comes to builing them, I is tha Geek.
LaneDart