Good Morning
Anyone know any good lessons online about Arrays in vb.net.
I am a hobbiest and stuggling to understand Arrays. Let me explain briefly
what I want to do.
I am writing a Poker Solutions Program purely for my oen fun and want to
shuffle a deck of cards. now the easiest way, i think, is to make an Array
that looks like this:
Card(0) = (FaceCard, SuitCard, RandomNumber)
Card(1) = (FaceCard, SuitCard, RandomNumber)
.......
Card(51) = (FaceCard, SuitCard, RandomNumber)
Card.Sort(2)
FaceCard and SuitCard would just run through a for next loop.
I've got the mechanics in my head but just getting my head around OOP which
I presume the Card would have to be an object I just dont know how to build
that array.
Cheers in advance 6 3672
Well, it's pretty easy.
Given a class, Card:
Public Class Card
....
End Class
Dim theDeck(51) As Card
"MC" <fd***@sdfas.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Good Morning
Anyone know any good lessons online about Arrays in vb.net.
I am a hobbiest and stuggling to understand Arrays. Let me explain briefly what I want to do.
I am writing a Poker Solutions Program purely for my oen fun and want to shuffle a deck of cards. now the easiest way, i think, is to make an Array that looks like this:
Card(0) = (FaceCard, SuitCard, RandomNumber) Card(1) = (FaceCard, SuitCard, RandomNumber) ...... Card(51) = (FaceCard, SuitCard, RandomNumber)
Card.Sort(2)
FaceCard and SuitCard would just run through a for next loop.
I've got the mechanics in my head but just getting my head around OOP which I presume the Card would have to be an object I just dont know how to build that array.
Cheers in advance
"MC" <fd***@sdfas.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Good Morning
Anyone know any good lessons online about Arrays in vb.net.
I am a hobbiest and stuggling to understand Arrays. Let me explain briefly what I want to do.
I am writing a Poker Solutions Program purely for my oen fun and want to shuffle a deck of cards. now the easiest way, i think, is to make an Array that looks like this:
Card(0) = (FaceCard, SuitCard, RandomNumber) Card(1) = (FaceCard, SuitCard, RandomNumber) ...... Card(51) = (FaceCard, SuitCard, RandomNumber)
Card.Sort(2)
FaceCard and SuitCard would just run through a for next loop.
I've got the mechanics in my head but just getting my head around OOP which I presume the Card would have to be an object I just dont know how to build that array.
Here's some code to get you started:
Class Cards
Public Enum Rank
Deuce
Trey
Four
Five
Six
Seven
Eight
Nine
Ten
Jack
Queen
King
Ace
End Enum
Public Enum Suit
Club
Diamond
Hart
Spade
End Enum
Public Structure Card
Public ReadOnly Rank As Rank
Public ReadOnly Suit As Suit
Public Sub New(ByVal Rank As Rank, ByVal Suit As Suit)
Me.Rank = Rank
Me.Suit = Suit
End Sub
Public Class CardOrder
Implements IComparer
Public Function Compare(ByVal x As Object, ByVal y As
Object) As Integer Implements System.Collecti ons.IComparer.C ompare
Dim cx As Card = DirectCast(x, Card)
Dim cy As Card = DirectCast(y, Card)
Return cx.Rank.Compare To(cy.Rank)
End Function
End Class
End Structure
Public Class Deck
'VB arrays are zero based and declared using their Upper Bound,
'not their number of elements
Private cards(51) As Card
Public Sub New()
Dim ix As Integer = 0
For r As Rank = Rank.Deuce To Rank.Ace
For s As Suit = Suit.Club To Suit.Spade
cards(ix) = New Card(r, s)
ix += 1
Next
Next
End Sub
Public Sub Shuffle()
Dim r As New Random
Dim xx As Card
For i As Integer = i To 1000
Dim c1 As Integer = r.Next(0, 51)
Dim c2 As Integer = r.Next(0, 51)
If c1 <> c2 Then
xx = cards(c1)
cards(c1) = cards(c2)
cards(c2) = xx
End If
Next
End Sub
End Class
End Class
David
another way to do the shuffle is to add a sequence nbr to the card.
Generate 52 random numbers in say the range 1-20000, setting the
sequence for each card to one of these
Sort by sequence.
Should give a pretty good random distribution for the cost of
generating 52 random numbers and sorting the deck.
hth,
Alan.
> another way to do the shuffle is to add a sequence nbr to the card.
Or just generate the pack already shuffled in an arraylist (modifying
David's code):-
Dim pack As ArrayList = New ArrayList(52)
Dim p As Integer
For s as Suit = Suit.Club To Suit.Spade
For r as Rank = Rank.Deuce To Rank.Ace
pack.Insert(Ran dom(0, p), New Card(r, s))
p += 1
Next
Next
Where Random is a function (thank you VB help):-
Function Random(ByVal lowerbound As Integer, ByVal upperbound As Integer)
Return CInt(Int((upper bound - lowerbound + 1) * Rnd() + lowerbound))
End Function
Andrew
Cool, lots of ways for me to experiment.
Cheers Guys
"MC" <fd***@sdfas.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Good Morning
Anyone know any good lessons online about Arrays in vb.net.
I am a hobbiest and stuggling to understand Arrays. Let me explain briefly what I want to do.
I am writing a Poker Solutions Program purely for my oen fun and want to shuffle a deck of cards. now the easiest way, i think, is to make an Array that looks like this:
Card(0) = (FaceCard, SuitCard, RandomNumber) Card(1) = (FaceCard, SuitCard, RandomNumber) ...... Card(51) = (FaceCard, SuitCard, RandomNumber)
Card.Sort(2)
FaceCard and SuitCard would just run through a for next loop.
I've got the mechanics in my head but just getting my head around OOP which I presume the Card would have to be an object I just dont know how to build that array.
Cheers in advance
Hi Folks. MC Again, thanks for your advice earlier,
i cracked it and i thought i'd share my final Deck Dealing with you. I know
have to figure out a solution to what hand am I holding. But thats for
another time.
Public Class DeckOfCards
Public Enum Suit
Clubs
Spades
Diamonds
Hearts
End Enum
Public Enum Face
Ace
Two
Three
Four
Five
Six
Seven
Eight
Nine
Ten
Jack
Queen
King
End Enum
Public Class Card
Implements IComparable
Public ReadOnly Suit As Suit
Public ReadOnly Face As Face
Public ReadOnly random As Integer
Public Sub New(ByVal suit As Suit, ByVal face As Face, ByVal Random As
Integer)
Me.Suit = suit
Me.Face = face
Me.random = Random
End Sub
Public Function CompareTo(ByVal obj As Object) As Integer Implements
System.ICompara ble.CompareTo
Dim c As Card = obj
Return (Me.random - c.random)
End Function
End Class
Public Shared Function Deck()
Dim pack As ArrayList = New ArrayList(51)
Dim r As New Random
For s As Suit = Suit.Clubs To Suit.Hearts
For f As Face = Face.Ace To Face.King
Dim m_card As New Card(s, f, r.Next(1, 99999))
pack.Add(m_card )
Next
Next
pack.Sort()
Return pack
End Function
End Class
Cheers guys
"MC" <fd***@sdfas.co m> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Good Morning
Anyone know any good lessons online about Arrays in vb.net.
I am a hobbiest and stuggling to understand Arrays. Let me explain briefly what I want to do.
I am writing a Poker Solutions Program purely for my oen fun and want to shuffle a deck of cards. now the easiest way, i think, is to make an Array that looks like this:
Card(0) = (FaceCard, SuitCard, RandomNumber) Card(1) = (FaceCard, SuitCard, RandomNumber) ...... Card(51) = (FaceCard, SuitCard, RandomNumber)
Card.Sort(2)
FaceCard and SuitCard would just run through a for next loop.
I've got the mechanics in my head but just getting my head around OOP which I presume the Card would have to be an object I just dont know how to build that array.
Cheers in advance This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Canonical Latin |
last post by:
"Leor Zolman" <leor@bdsoft.com> wrote
> "Canonical Latin" <javaplus@hotmail.com> wrote:
>
> > ...
> >But I'm still curious as to the rational of having type
> >pointer-to-array-of-size-N-of-type-T (which is fine) and not having type
> >array-of-size-N-of-type-T (with some exceptions, which is curious).
> > So far
> >the consensus seems to be that while everyone is aware of this no one
knows
|
by: Matteo Settenvini |
last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using
g++ 3.3.x.
I had been taught that an array isn't a lot different from a pointer
(in fact you can use the pointer arithmetics to "browse" it). So I
expected that when I run this program, I get both c1.A and c2.A
pointing to the same address, and changing c1.A means that also c2.A
changes too.
----- BEGIN example CODE -----------
|
by: JezB |
last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of
files that match one of 3 search patterns, so I need something like
DirectoryInfo ld = new DirectoryInfo(searchDir);
pfiles = ld.GetFiles("*.aspx.resx|") + ld.GetFiles("*.ascx.resx") +
ld.GetFiles("*.master.resx");
but of course there is no + operation allowed on the FileInfo arrays
returned by the GetFiles method.
|
by: Michel Rouzic |
last post by:
It's the first time I try using structs, and I'm getting confused with
it and can't make it work properly
I firstly define the structure by this : typedef struct { char *l1; int
*l2; int Nval; } *arrays;
It's supposed to be a structure containing an array of chars, an array
of ints and an int.
I declare functions like this : arrays *parseline(char *line, int N)
|
by: Rob Griffiths |
last post by:
Can anyone explain to me the difference between an element type and a
component type?
In the java literature, arrays are said to have component types, whereas
collections from the Collections Framework are said to have an element
type.
http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html
| |
by: Rene Nyffenegger |
last post by:
Hello everyone.
I am not fluent in JavaScript, so I might overlook the obvious.
But in all other programming languages that I know and that
have associative arrays, or hashes, the elements in the
hash are alphabetically sorted if the key happens to
be alpha numeric. Which I believe makes sense because
it allows for fast lookup of a key.
|
by: Robert Bravery |
last post by:
Hi all,
Can some one show me how to achieve a cross product of arrays. So that if I
had two arrays (could be any number) with three elements in each (once again
could be any number) I would get:
the two arrays
{"one","two","three"},{"red","green","blue}
the result
one red
one green
|
by: Doug_J_W |
last post by:
I have a Visual Basic (2005) project that contains around twenty
embedded text files as resources. The text files contain two columns
of real numbers that are separated by tab deliminator, and are of
different lengths (e.g. usually between 25 and 45 rows. The columns in
each file have the same length). The text files have been numbered
sequentially e.g. cb0, cb1, cb2 and so on. I would like to read the
data from each text file into...
|
by: mike3 |
last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms-
windows.programmer.win32
since there's Windows material in here as well as questions related to
standard
C++. Not sure how that'd go over at just comp.lang.c++. If one of
these groups is
too inappropriate, just take it off from where you send your replies.)
Hi.
|
by: weaknessforcats |
last post by:
Arrays Revealed
Introduction
Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with
arrays and array syntax but is not clear on a )exactly how multi-dimensional arrays work, b) how to call
a function with a multi-dimensional array, c) how to return a multi-dimensional array from a function,
or d) how to read and write arrays from a disc file.
Note to C++ programmers: You should be using...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |