$CASE/06f522/lechner/setengineagREV3_cgrev4.dif

Message 7/1466  From Chris Guffey                   Nov 28, 06 10:30:17 PM -0500


DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
> From cguffey@gmail.com  Tue Nov 28 22:30:25 2006
Message 10/1468  From Chris Guffey   Nov 28, 06 10:23:27 PM -0500

To: "Keith Bagley" <kbagley@us.ibm.com>
Subject: Re: Final Project path (scketches)
Cc: all

I updated the SetEngine code.
Changes:
- I made all data members private, this forced me to add some access member
functions to the CARD class
- As per our class discussion I removed x, y from BOARD_SLOT and replaced
that with m_nSlotId. This adds some flexibility as to how we want to display
the cards. It also makes it easier to modify the code further if we're to
have more slots on the board for whatever reason in future. Ideally I'd like
to refactor the CARD and DECK classes to be abstract and specifically make a
SETCARD and SETDECK class. That way it might be possible to have the DEALER
work with any kind of card deck, not just a set game deck. That is likely
out of the scope of this assignment however. Similarly with the BOARD I'm
trying to keep open the possibility the class could be used in conjuction
with any kind of card deck.
- I trimmed down the BOARD class with respect to the changes made above, a
couple functions were for the benefit of a  (x,y) system and are not needed
when using a slot id.
- I added a BOARD::SwapSlots(...) method, again this is with future
enhancements in mind. As prof. Lechner stated he'd like to move cards around
on the board to order them how ever he sees fit. This function will make
that possible.
- I tested my kooky shuffle algorithm and it seems to work. It had a bug in
it that was easily found and fixed.
- Finally I updated the main function to reflect the changes. Keep in mind
that this 'main' function is not meant to eventually become our true main
function, it is only here to show how to use the classes I've written.
Anthony please review this function and let me know if there's anything
you're not sure of.

I'd also like to clarify that the previous ERD I wrote and Keith
subsequently has maintained and corrected were only relevent to the classes
I wrote here and was not intended to reflect the entire system. It was only
meant to be a piece of the puzzle.
================================================================
-------------------
mercury(43)> diff setengine.cpp ../../../agabriel/FinalProject/GUI/REV3|wc
    275    1058    9011
mercury(44)> pwd
/nfs/galaxy/misc/proj3/case/06f522/cguffey/final_project/rev4
mercury(45)> diff setengine.cpp ../../../agabriel/FinalProject/GUI/REV3 | wc
    275    1058    9011
mercury(46)> diff setengine.cpp ../../../agabriel/FinalProject/GUI/REV3 >../../../lechner/setengineagREV3_cgrev4.dif
--------------------

1,5d0
< /******************************************************
< * AUTHORS: Chris Guffey
< * FILENAME: SetEngine.cpp
< * DATE: 11/28/06
< ******************************************************/
6a2
> #include "stdafx.h"
9d4
< #include <stdio.h>
13,17d7
< int CARD::GetId() const
< {
<         return m_nId;
< }
< 
22c12
<         m_nId = nId;
---
>         m_nIndex = nId;
31,50d20
< CARD_COLOR CARD::GetColor() const
< {
<         return m_nColor;
< }
< 
< CARD_SHAPE CARD::GetShape() const
< {
<         return m_nShape;
< }
< 
< CARD_NUMBER CARD::GetNumber() const
< {
<         return m_nNumber;
< }
< 
< CARD_DESIGN CARD::GetDesign() const
< {
<         return m_nDesign;
< }
< 
76c46
<         int nColor = (int) pCard1->GetColor() + (int) pCard2->GetColor() + (int) pCard3->GetColor();
---
>         int nColor = (int) pCard1->m_nColor + (int) pCard2->m_nColor + (int) pCard3->m_nColor;
84c54
<         int nShape = (int) pCard1->GetShape() + (int) pCard2->GetShape() + (int) pCard3->GetShape();
---
>         int nShape = (int) pCard1->m_nShape + (int) pCard2->m_nShape + (int) pCard3->m_nShape;
92c62
<         int nNumber = (int) pCard1->GetNumber() + (int) pCard2->GetNumber() + (int) pCard3->GetNumber();
---
>         int nNumber = (int) pCard1->m_nNumber + (int) pCard2->m_nNumber + (int) pCard3->m_nNumber;
100c70
<         int nDesign = (int) pCard1->GetDesign() + (int) pCard2->GetDesign() + (int) pCard3->GetDesign();
---
>         int nDesign = (int) pCard1->m_nDesign + (int) pCard2->m_nDesign + (int) pCard3->m_nDesign;
163c133
< bool BOARD_SLOT::InitializeSlot(int nSlot)
---
> bool BOARD_SLOT::InitializeSlot(int x, int y)
165c135,136
<         m_nSlotId = nSlot;
---
>         m_nX = x;
>         m_nY = y;
184,185c155,157
<         for (int i = 0; i < MAX_BOARD_SLOTS; i++)
<                         m_Slots[i].InitializeSlot(i);
---
>         for (int x = 0; x < BOARD_X_SIZE; x++)
>                 for (int y = 0; y < BOARD_Y_SIZE; y++)
>                         m_Slots[x][y].InitializeSlot(x,y);
190c162
< const CARD* BOARD::GetCardInSlot(int nSlot) const
---
> const CARD* BOARD::GetCardInSlot(int x, int y) const
192c164
<         if (false == TestBound(nSlot))
---
>         if (false == TestBound(x, y))
195c167
<         return m_Slots[nSlot].GetCard();
---
>         return m_Slots[x][y].GetCard();
198c170
< bool BOARD::ReplaceCardInSlot(int nSlot, CARD* pCard)
---
> bool BOARD::FindSlot(int nIndex, int* pX, int* pY) const
200,201c172
<         if (false == TestBound(nSlot))
<                 return false;
---
>         if (0 == pX || 0 == pY) return false;
203c174,179
<         m_Slots[nSlot].SetCard(pCard);
---
>         for (int x = 0; x < BOARD_X_SIZE; x++)
>         {
>                 for (int y = 0; y < BOARD_Y_SIZE; y++)
>                 {
>                         const CARD* pCard = m_Slots[x][y].GetCard();
>                         if (0 == pCard) continue;
204a181,184
>                         if (nIndex == pCard->m_nIndex)
>                         {
>                                 *pX = x;
>                                 *pY = y;
206a187,188
>                 }
>         }
208c190,193
< bool BOARD::SwapSlots(int nSlot1, int nSlot2)
---
>         return false;
> }
> 
> bool BOARD::ReplaceCardInSlot(int nIndex, CARD* pCard)
210c195,196
<         if (false == TestBound(nSlot1) || false == TestBound(nSlot2))
---
>         int nX = 0, nY = 0;
>         if (false == FindSlot(nIndex, &nX, &nY))
213,214c199,210
<         const CARD* pCard1 = GetCardInSlot(nSlot1);
<         const CARD* pCard2 = GetCardInSlot(nSlot2);
---
>         if (false == TestBound(nX, nY))
>                 return false;
> 
>         m_Slots[nX][nY].SetCard(pCard);
> 
>         return true;
> }
> 
> bool BOARD::ReplaceCardInSlot(int x, int y, CARD* pCard)
> {
>         if (false == TestBound(x, y))
>                 return false;
216,217c212
<         ReplaceCardInSlot(nSlot2, (CARD*) pCard1);
<         ReplaceCardInSlot(nSlot1, (CARD*) pCard2);
---
>         m_Slots[x][y].SetCard(pCard);
222c217
< bool BOARD::TestBound(int nSlot) const
---
> bool BOARD::TestBound(int x, int y) const
224c219,220
<         if (0 > nSlot || MAX_BOARD_SLOTS <= nSlot)
---
>         if (0 > x || BOARD_X_SIZE <= x ||
>                 0 > y || BOARD_Y_SIZE <= y)
229a226
> 
270d266
<         /* assign a random numner for each card in the deck */
274,275d269
<         /* determine the order of the deck based on the random number assigned
<         with the higest number becoming the top card in the deck */
284c278
<                 nOrder[m_nDeckOrder[i]] = -1;
---
>                 nOrder[i] = -1;
320c314,316
<         for (int nSlot = 0; nSlot < MAX_BOARD_SLOTS; nSlot++)
---
>         for (int x = 0; x < BOARD_X_SIZE; x++)
>         {
>                 for (int y = 0; y < BOARD_Y_SIZE; y++)
322c318
<                 const CARD* pCardOnBoard = pBoard->GetCardInSlot(nSlot);
---
>                         const CARD* pCardOnBoard = pBoard->GetCardInSlot(x, y);
332c328,329
<                         pBoard->ReplaceCardInSlot(nSlot, (CARD*) pNextCard);
---
>                                 pBoard->ReplaceCardInSlot(x, y, (CARD*) pNextCard);
>                         }
354,364c351
< void DEALER::DisplayDeckOrder() const
< {
<         printf("\nBegin Printing Deck Order:\n");
<         for (int i = 0; i < CARDS_IN_DECK; i++)
<         {
<                 printf("%d ", m_nDeckOrder[i]);
< 
<         }
<         printf("\nEnd Printing Deck Order:\n");
< }
< 
---
> #ifdef STANDALONE
373d359
<         dealer.DisplayDeckOrder();
383c369,371
<         for (int nSlot = 0; nSlot < MAX_BOARD_SLOTS; nSlot++)
---
>         for (int x = 0; x < BOARD_X_SIZE; x++)
>         {
>                 for (int y = 0; y < BOARD_Y_SIZE; y++)
386,387c374,376
<                 const CARD* pCard = board.GetCardInSlot(nSlot);
<                 /* graphics->DrawSlot(nSlot, pCard) */
---
>                         const CARD* pCard = board.GetCardInSlot(x, y);
>                         /* graphics->DrawSlot(x, y, pCard) */
>                 }
393c382
<                 int nCardId1 = 0, nCardId2 = 0, nCardId3 = 0; /* represent card slots */
---
>                 int nCard1 = 0, nCard2 = 0, nCard3 = 0; /* represent card indexes */
394a384,385
>                 /* use one of EXMAPLE1 or EXAMPLE2 */
>                 {
397c388
<                 /* player->GetSelection(nCard1, nCardId2, nCardId3); */
---
>                         /* player->GetSelection(nCard1, nard2, nCard3); */
399c390
<                 if (true == dealer.IsASet(nCardId1, nCardId2, nCardId3))
---
>                         if (true == dealer.IsASet(nCard1, nCard2, nCard3))
402,404c393,395
<                         board.ReplaceCardInSlot(nCardId1, 0);
<                         board.ReplaceCardInSlot(nCardId2, 0);
<                         board.ReplaceCardInSlot(nCardId3, 0);
---
>                                 board.ReplaceCardInSlot(nCard1, 0);
>                                 board.ReplaceCardInSlot(nCard2, 0);
>                                 board.ReplaceCardInSlot(nCard3, 0);
405a397
>                                 /* do network and graphics stuff to update everyone */
407c399,400
<                 else
---
>                 }
> 
409c402,420
<                         /* player.DecrementScore(); */
---
>                         /* EXAMPLE2: UI returns (x,y) coords of selected cards */
>                         int x1 = 0, y1 = 0;
>                         int x2 = 0, y2 = 0;
>                         int x3 = 0, y3 = 0;
> 
>                         /* player.GetSelection(x1,y1,x2,y2,x3,y3) */
> 
>                         const CARD* pCard1 = board.GetCardInSlot(x1, y1);
>                         const CARD* pCard2 = board.GetCardInSlot(x2, y2);
>                         const CARD* pCard3 = board.GetCardInSlot(x3, y3);
> 
>                         /* UI should be smart enough to not allow the user to 
>                         select an empty slot but just in case */
>                         if (0 == pCard1 || 0 == pCard2 || 0 == pCard3)
>                                 continue; 
> 
>                         nCard1 = pCard1->m_nIndex;
>                         nCard2 = pCard2->m_nIndex;
>                         nCard3 = pCard3->m_nIndex;
411a423,430
>                 /* back to main code */
>                 if (true == dealer.IsASet(nCard1, nCard2, nCard3))
>                 {
>                         /* player.IncrementScore(); */
>                         board.ReplaceCardInSlot(nCard1, 0);
>                         board.ReplaceCardInSlot(nCard2, 0);
>                         board.ReplaceCardInSlot(nCard3, 0);
>                         dealer.FillEmptyBoardSlots(&board);
412a432,433
>                 }
> 
419a441
> #endif
\ No newline at end of file
=============================================================

setengine.h.dif:
-----------------------------------------


     61     194    1605
1,6d0
< /******************************************************
< * AUTHORS: Chris Guffey
< * FILENAME: SetEngine.h
< * DATE: 11/28/06
< ******************************************************/
< 
9,10d2
< typedef char bool; const bool false = 0; const bool true = 1;
< 
15a8
> //#define STANDALONE
17,18c10,11
< #define MAX_BOARD_SLOTS 12
< 
---
> #define BOARD_X_SIZE 4
> #define BOARD_Y_SIZE 3
25,32c18
<         int GetId() const;
<         CARD_COLOR GetColor() const;
<         CARD_SHAPE GetShape() const;
<         CARD_NUMBER GetNumber() const;
<         CARD_DESIGN GetDesign() const;
< 
< private:
<         int m_nId;
---
>         int m_nIndex;
56d41
< private:
63c48
<         bool InitializeSlot(int nSlot);
---
>         bool InitializeSlot(int x, int y);
67,68c52,53
< private:
<         int m_nSlotId;
---
>         int m_nX;
>         int m_nY;
76,79c61,65
<         const CARD* GetCardInSlot(int nSlot) const;
<         bool ReplaceCardInSlot(int nSlot, CARD* pCard);
<         bool SwapSlots(int nSlot1, int nSlot2);
<         bool TestBound(int nSlot) const;
---
>         const CARD* GetCardInSlot(int x, int y) const;
>         bool FindSlot(int nIndex, int* pX, int* pY) const;
>         bool ReplaceCardInSlot(int nIndex, CARD* pCard);
>         bool ReplaceCardInSlot(int x, int y, CARD* pCard);
>         bool TestBound(int x, int y) const;
81,82c67
< private:
<         BOARD_SLOT m_Slots[MAX_BOARD_SLOTS];
---
>         BOARD_SLOT m_Slots[BOARD_X_SIZE][BOARD_Y_SIZE];
98d82
<         void DisplayDeckOrder() const;
100d83
< private:

