Arrays

working with arrays

Page 1 of 1

10 Replies - 1566 Views - Last Post: 01 February 2007 - 10:57 AM Rate Topic: -----

#1 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

Arrays

Posted 31 January 2007 - 09:38 AM

ok so i am writing black jack and i have private sub DealCard which prettymuch picks a random card then saves it in a (2,100) aray (I just use a hundred because it can hold many cards). So what i do is all the 1,Anything arrays are the player and 2,Anything are AIs. Anyway when i deal the card i want to see if it is the same as anyother array is there away to do this without saying
If Cards(1,1) = Cards(1,2) or Cards1,1 = 1,3 and so on ?


is there a way to do it without saying that by just saying like check for the same throughout the whole array? Any help would be apprechiated
Thnlx
John

Is This A Good Question/Topic? 0
  • +

Replies To: Arrays

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Arrays

Posted 31 January 2007 - 09:41 AM

Well, the most immediate way would be to use a loop to go through the array.
Was This Post Helpful? 0
  • +
  • -

#3 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

Re: Arrays

Posted 31 January 2007 - 10:00 AM

View PostAmadeus, on 31 Jan, 2007 - 09:41 AM, said:

Well, the most immediate way would be to use a loop to go through the array.

could i do that like this
Dim X = 0
Dim Y = 1
DIm cards (2,6)
Dim Counter As Integer
For Counter = 1 to 12
x = x + 1
If X > 6 Then
X = 1
Y = 2
End If
if card(1,1) = Card(y,x) then
msgbox("ill put the rest here")
End If
Next Counter


Would That Work?
thnx
John
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Arrays

Posted 31 January 2007 - 10:03 AM

What exactly is it you wish to do? Imagine you have dealt a card - what do you want to do now? Do you want to check it against every other card in the array (both player and AI) to see if there is a duplicate?
Was This Post Helpful? 0
  • +
  • -

#5 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

Re: Arrays

Posted 31 January 2007 - 10:10 AM

View PostAmadeus, on 31 Jan, 2007 - 10:03 AM, said:

What exactly is it you wish to do? Imagine you have dealt a card - what do you want to do now? Do you want to check it against every other card in the array (both player and AI) to see if there is a duplicate?

yes thats exactly what i want to do will this code work for it?
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Arrays

Posted 31 January 2007 - 10:27 AM

Not really. You'll really want a double loop (loop within a loop). We may be able to save some time, however....if you have an array of (2,100), meaning that there are spots for essentially 200 cards, you will definitely have repeats.
Was This Post Helpful? 0
  • +
  • -

#7 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

Re: Arrays

Posted 31 January 2007 - 11:31 AM

ok i wrote something to do the same thing without a loop here it is but it acully is the code to completely deal the cards
Public Class Form1
	Dim Suit As Integer
	Dim Number As Integer
	Dim Cards(4, 13)
	Dim MyCard As String
	Dim X = 0
	Dim y = 0
	Dim A = 0
	Dim B = 1
	Dim c = 0
	Dim dealtcards(2, 13)
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		y = 1
		DealMyCards()
		DealMyCards()
		y = 2
		DealMyCards()
		DealMyCards()
	End Sub
	Private Sub DealMyCards()
		If y = 1 Then
			X = X + 1
			DeclareArray()
			Suit = Int(Rnd() * 3) + 1
			Number = Int(Rnd() * 12) + 1
			MyCard = Cards(Suit, Number)
			Checkforduplicates()
			dealtcards(y, X) = MyCard
			SettingArrayToCard()
		End If
		If y = 2 Then
			c = c + 1
			DeclareArray()
			Suit = Int(Rnd() * 3) + 1
			Number = Int(Rnd() * 12) + 1
			MyCard = Cards(Suit, Number)
			Checkforduplicates()
			dealtcards(y, c) = MyCard
			SettingArrayToCard()
		End If
	End Sub
	Private Sub Checkforduplicates()
Again:  A = A + 1
		If A > 6 Then
			A = 1
			B = 2
		End If
		If MyCard = dealtcards(B, A) Then
			DealMyCards()
		End If
		If A < 6 Or B < 2 Then
			GoTo Again
		End If
	End Sub
	Private Sub DeclareArray()
		Cards(1, 1) = "Ace Of Clubs"
		Cards(1, 2) = "Two Of Clubs"
		Cards(1, 3) = "Three Of Clubs"
		Cards(1, 4) = "Four Of Clubs"
		Cards(1, 5) = "Five Of Clubs"
		Cards(1, 6) = "Six Of Clubs"
		Cards(1, 7) = "Seven Of Clubs"
		Cards(1, 8) = "Eight Of Clubs"
		Cards(1, 9) = "Nine Of Clubs"
		Cards(1, 10) = "Ten Of Clubs"
		Cards(1, 11) = "Jack Of Clubs"
		Cards(1, 12) = "Queen Of Clubs"
		Cards(1, 13) = "King Of Clubs"
		Cards(2, 1) = "Ace Of Hearts"
		Cards(2, 2) = "Two Of Hearts"
		Cards(2, 3) = "Three Of Hearts"
		Cards(2, 4) = "Four Of Hearts"
		Cards(2, 5) = "Five Of Hearts"
		Cards(2, 6) = "Six Of Hearts"
		Cards(2, 7) = "Seven Of Hearts"
		Cards(2, 8) = "Eight Of Hearts"
		Cards(2, 9) = "Nine Of Hearts"
		Cards(2, 10) = "Ten Of Hearts"
		Cards(2, 11) = "Jack Of Hearts"
		Cards(2, 12) = "Queen Of Hearts"
		Cards(2, 13) = "King Of Hearts"
		Cards(3, 1) = "Ace Of Spades"
		Cards(3, 2) = "Two Of Spades"
		Cards(3, 3) = "Three Of Spades"
		Cards(3, 4) = "Four Of Spades"
		Cards(3, 5) = "Five Of Spades"
		Cards(3, 6) = "Six Of Spades"
		Cards(3, 7) = "Seven Of Spades"
		Cards(3, 8) = "Eight Of Spades"
		Cards(3, 9) = "Nine Of Spades"
		Cards(3, 10) = "Ten Of Spades"
		Cards(3, 11) = "Jack Of Spades"
		Cards(3, 12) = "Queen Of Spades"
		Cards(3, 13) = "King Of Spades"
		Cards(4, 1) = "Ace Of Dimonds"
		Cards(4, 2) = "Two Of Dimonds"
		Cards(4, 3) = "Three Of Dimonds"
		Cards(4, 4) = "Four Of Dimonds"
		Cards(4, 5) = "Five Of Dimonds"
		Cards(4, 6) = "Six Of Dimonds"
		Cards(4, 7) = "Seven Of Dimonds"
		Cards(4, 8) = "Eight Of Dimonds"
		Cards(4, 9) = "Nine Of Dimonds"
		Cards(4, 10) = "Ten Of Dimonds"
		Cards(4, 11) = "Jack Of Dimonds"
		Cards(4, 12) = "Queen Of Dimonds"
		Cards(4, 13) = "King Of Dimonds"
	End Sub
	Private Sub SettingArrayToCard()
		Label1.Text = dealtcards(1, 1)
		Label2.Text = dealtcards(1, 2)
		Label3.Text = dealtcards(1, 3)
		Label4.Text = dealtcards(1, 4)
		Label5.Text = dealtcards(1, 5)
		Label6.Text = dealtcards(1, 6)
		Label7.Text = dealtcards(1, 7)
		Label8.Text = dealtcards(1, 8)
		Label9.Text = dealtcards(1, 9)
		Label10.Text = dealtcards(1, 10)
		Label11.Text = dealtcards(1, 11)
		Label12.Text = dealtcards(1, 12)
		Label13.Text = dealtcards(1, 13)
		Label14.Text = dealtcards(2, 1)
		Label15.Text = dealtcards(2, 2)
		Label16.Text = dealtcards(2, 3)
		Label17.Text = dealtcards(2, 4)
		Label18.Text = dealtcards(2, 5)
		Label19.Text = dealtcards(2, 6)
		Label20.Text = dealtcards(2, 7)
		Label21.Text = dealtcards(2, 8)
		Label22.Text = dealtcards(2, 9)
		Label23.Text = dealtcards(2, 10)
		Label24.Text = dealtcards(2, 11)
		Label25.Text = dealtcards(2, 12)
		Label26.Text = dealtcards(2, 13)
	End Sub
End Class


the problem is when i start it and click deal the 2 cards on the bottom work but on the top (the AI) it has the first card skips one then comes up could help me find the problem
thnxs
john
Was This Post Helpful? 0
  • +
  • -

#8 KeyWiz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 438
  • Joined: 26-October 06

Re: Arrays

Posted 01 February 2007 - 12:06 AM

If you instead create a listbox, and place all the cards in the list,
as you remove cards, the list will no longer have that card,
just like a real deck!
eliminates the comparison problem
Was This Post Helpful? 0
  • +
  • -

#9 KeyWiz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 438
  • Joined: 26-October 06

Re: Arrays

Posted 01 February 2007 - 12:11 AM

hint: the holders of cards can also be lists
Was This Post Helpful? 0
  • +
  • -

#10 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

Re: Arrays

Posted 01 February 2007 - 07:42 AM

thnx a bunch I'll do that but how do you use a list box
Im new to programing as you might notice
thnx
john
Was This Post Helpful? 0
  • +
  • -

#11 KeyWiz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 438
  • Joined: 26-October 06

Re: Arrays

Post icon  Posted 01 February 2007 - 10:57 AM

I'm really sorry, I know this shit, but the meds
are not letting me do it, in VB6 it is
different than vb2005

in vb6, you would use something like

lstDeck.AddItem (myCard)


in VB2005 I think it's

lstDeck.Items.Add (myCardName)

I think, sorry again, too much pain to work through.

There is more to it, maybe look up the HELP on List-Combo Boxes
in VB2005 Help or VB6 Help

This post has been edited by KeyWiz: 01 February 2007 - 10:58 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1