Rob
http://code.google.com/p/ardb/source/detail?r=247
Modified:
/trunk/wxARDB/src/drawsimulator.cpp
/trunk/wxARDB/src/drawsimulator.h
=======================================
--- /trunk/wxARDB/src/drawsimulator.cpp Mon Feb 1 11:38:33 2010
+++ /trunk/wxARDB/src/drawsimulator.cpp Tue Aug 17 19:22:13 2010
@@ -26,6 +26,7 @@
#include "interfacedata.h"
#include <stdlib.h>
+#include <algorithm> // for std::random_shuffle
BEGIN_EVENT_TABLE(DrawSimulator, wxFrame)
@@ -118,9 +119,7 @@
DrawSimulator::Draw ()
{
DeckModel *pDeckModel = DeckModel::Instance ();
- int iRandomNumber;
long lCount;
- wxArrayString oTempArray;
wxString sName;
// Vampires
@@ -128,7 +127,6 @@
m_oRemainingVampires.Clear ();
if (pDeckModel->GetCryptList () && pDeckModel->GetCryptCount () > 0) {
- oTempArray.Clear ();
// Break down the numbered list into a flat list
for (unsigned int i = 0; i < pDeckModel->GetCryptList ()->GetCount
(); i++) {
for (pDeckModel->GetCryptList ()->Item (i).Item (0).ToLong
(&lCount);
@@ -140,21 +138,18 @@
<< wxT (" (")
<< pDeckModel->GetCryptList ()->Item (i).Item (3)
<< wxT (")");
- oTempArray.Add (sName);
+ m_oRemainingVampires.Add (sName);
}
}
- // Shuffle the cards into a new list
- for (unsigned int i = oTempArray.GetCount (); i > 0; i--) {
- iRandomNumber = Random (i);
- sName = oTempArray.Item (iRandomNumber);
- m_oRemainingVampires.Add (sName);
- oTempArray.RemoveAt (iRandomNumber);
- }
+
+ // Shuffle the list of crypt card names stored in
m_oRemainingVampires
+ std::random_shuffle(&m_oRemainingVampires[0],
+
&m_oRemainingVampires[m_oRemainingVampires.GetCount ()]);
+
// Draw cards
for (unsigned int i = 0; i < 4 && m_oRemainingVampires.GetCount
(); i++) {
- iRandomNumber = Random (m_oRemainingVampires.GetCount ());
- m_oDrawnVampires.Add (m_oRemainingVampires.Item
(iRandomNumber));
- m_oRemainingVampires.RemoveAt (iRandomNumber);
+ m_oDrawnVampires.Add (m_oRemainingVampires.Item (i));
+ m_oRemainingVampires.RemoveAt (i);
}
// Display stuff
m_pDrawnVampiresText->Freeze ();
@@ -182,26 +177,22 @@
m_oRemainingCards.Clear ();
if (pDeckModel->GetLibraryList () && pDeckModel->GetLibraryCount () >
0) {
- oTempArray.Clear ();
// Break down the numbered list into a flat list
for (unsigned int i = 0; i < pDeckModel->GetLibraryList
()->GetCount (); i++) {
for (pDeckModel->GetLibraryList ()->Item (i).Item (0).ToLong
(&lCount);
lCount > 0; lCount--) {
- oTempArray.Add ( pDeckModel->GetLibraryList ()->Item
(i).Item (1));
+ m_oRemainingCards.Add ( pDeckModel->GetLibraryList
()->Item (i).Item (1));
}
}
- // Shuffle the cards into a new list
- for (unsigned int i = oTempArray.GetCount (); i > 0; i--) {
- iRandomNumber = Random (i);
- sName = oTempArray.Item (iRandomNumber);
- m_oRemainingCards.Add (sName);
- oTempArray.RemoveAt (iRandomNumber);
- }
+
+ // Shuffle the list of library card names stored in
m_oRemainingCards
+ std::random_shuffle(&m_oRemainingCards[0],
+ &m_oRemainingCards[m_oRemainingCards.GetCount
()]);
+
// Draw cards
for (unsigned int i = 0; i < 7 && m_oRemainingCards.GetCount ();
i++) {
- iRandomNumber = Random (m_oRemainingCards.GetCount ());
- m_oDrawnCards.Add (m_oRemainingCards.Item (iRandomNumber));
- m_oRemainingCards.RemoveAt (iRandomNumber);
+ m_oDrawnCards.Add (m_oRemainingCards.Item (i));
+ m_oRemainingCards.RemoveAt (i);
}
// Display stuff
m_pDrawnCardsText->Freeze ();
@@ -238,10 +229,3 @@
{
Draw ();
}
-
-
-int
-DrawSimulator::Random (int iMax)
-{
- return (int) (iMax * (rand() * 1.0) / RAND_MAX);
-}
=======================================
--- /trunk/wxARDB/src/drawsimulator.h Fri Feb 12 13:32:02 2010
+++ /trunk/wxARDB/src/drawsimulator.h Tue Aug 17 19:22:13 2010
@@ -48,7 +48,6 @@
void Draw ();
void OnButtonClose (wxCommandEvent & WXUNUSED (event));
void OnButtonDraw (wxCommandEvent & WXUNUSED (event));
- int Random (int iMax);
enum {
ID_CLOSE_BUTTON = wxID_HIGHEST + 1,