Exemplo n.º 1
0
//-----------------------------------------------------------------------------
// Purpose: Start a battle. Spawn all the players, and begin the countdown.
//-----------------------------------------------------------------------------
void CDiscArena::StartBattle( void )
{
	m_iCurrRound = 0;
	m_iTeamOneScore = m_iTeamTwoScore = 0;

	// First, set all players in this arena to "didn't play"
	for ( int i = 1; i <= gpGlobals->maxClients; i++ )
	{
		CBasePlayer *pPlayer = (CBasePlayer *)UTIL_PlayerByIndex( i );

		if (pPlayer && (pPlayer->m_pCurrentArena == this) && pPlayer->m_bHasDisconnected != TRUE )
			pPlayer->m_iLastGameResult = GAME_DIDNTPLAY;
	}

	// Get the players in the battle
	for ( i = 0; i < (m_iPlayersPerTeam * 2); i++ )
	{
		CBasePlayer *pCurr;

		// Check to see if this slot's already full
		if ( m_hCombatants[ i ] )
		{
			pCurr = (CBasePlayer*)(CBaseEntity*)m_hCombatants[ i ];
		}
		else
		{
			// Pop a new player from the queue
			pCurr = GetNextPlayer();
			if (!pCurr)
			{
				// Couldnt get enough players. Reset.
				Reset();
				return;
			}
		}

		// Set her team number
		if ( i < m_iPlayersPerTeam )
			pCurr->pev->team = 1;
		else
			pCurr->pev->team = 2;
		pCurr->pev->iuser4 = pCurr->pev->team;

		char sz[128];
		sprintf(sz, "Arena %d", pev->groupinfo );
		MESSAGE_BEGIN( MSG_ALL, gmsgTeamInfo );
			WRITE_BYTE( pCurr->entindex() );
			WRITE_STRING( sz );
		MESSAGE_END();

		// Add her to the list of combatants
		m_hCombatants[ i ] = pCurr;
		
		// Force her to update her clientinfo, so her colors match her team
		ClientUserInfoChanged( pCurr->edict(), g_engfuncs.pfnGetInfoKeyBuffer( pCurr->edict() ) );
	}

	// Start the first round
	StartRound();
}
Exemplo n.º 2
0
int GameManager::Run()
{
	if (players.size()==0)
	{
		return -1;
	}
	currentPlayer=players.end()-1;//end()-1 is to call GetNextPlayer() later

	ChessPoint currentCP(0,0);
	Result state=Result::ToBeContinued;
	do
	{
		std::cout<<cb->GetSum()+1<<": ";

		GetNextPlayer();
		currentCP=(*currentPlayer)->DoInput();
		state=SendToRuler(currentCP);
	} while (state==Result::ToBeContinued);

	if (state==HasWinner)
	{
		return (*currentPlayer)->GetId();
	}

	if (state==NoWinner)
	{
		return 0;
	}

	return -1;

}
Exemplo n.º 3
0
//---------------------------------------------------------------------------
void TFormMain::CheckTwoOther(int& xMove,int& yMove) const
{
  assert(xMove == -1 && yMove == -1);
  const std::vector<GameMove> moves1(GetTwoHorizontalOtherMoves());
  const std::vector<GameMove> moves2(GetTwoVerticalOtherMoves());
  const std::vector<GameMove> moves(Concatenate(moves1,moves2));
  assert(moves.size() == moves1.size() + moves2.size());

  const int nMoves = moves.size();
  if (nMoves==0) return;

  { //Get moves anti-player
    std::vector<GameMove> antiPlayerMoves;
    for (int i=0; i<nMoves; ++i)
    {
      assert(IsValidMove(moves[i]));
      if (IsRobot(moves[i].anti) == false) antiPlayerMoves.push_back(moves[i]);
    }
    //If there are anti-player moves, choose one at random
    if (antiPlayerMoves.empty()==false)
    {
      const int nAntiPlayerMoves = antiPlayerMoves.size();
      const int index = std::rand() % nAntiPlayerMoves;
      xMove = antiPlayerMoves[index].x;
      yMove = antiPlayerMoves[index].y;
      assert(IsValidMove(xMove,yMove));
      return;
    }
  }
  { //Get moves anti-next-player
    std::vector<GameMove> antiNextPlayerMoves;
    for (int i=0; i<nMoves; ++i)
    {
      if (GetNextPlayer(mPlayer) == moves[i].anti) antiNextPlayerMoves.push_back(moves[i]);
    }
    //If there are anti-next-player moves, choose one at random
    if (antiNextPlayerMoves.empty()==false)
    {
      const int nAntiNextPlayerMoves = antiNextPlayerMoves.size();
      const int index = std::rand() % nAntiNextPlayerMoves;
      xMove = antiNextPlayerMoves[index].x;
      yMove = antiNextPlayerMoves[index].y;
      assert(IsValidMove(xMove,yMove));
      return;
    }
  }
  //Choose a move at random
  {
    const int index = std::rand() % nMoves;
    xMove = moves[index].x;
    yMove = moves[index].y;
    assert(IsValidMove(xMove,yMove));
  }
}
void ConnectThree::DoMove(const int x, const int y)
{
  assert(
    (CreateInvalidMove().get<0>() == x
      && CreateInvalidMove().get<1>() == y)
    || CanDoMove(x,y));
  if (CreateInvalidMove().get<0>() == x
    && CreateInvalidMove().get<1>() == y)
  {
    return;
  }
  m_area[x][y] = m_player;
  m_player = GetNextPlayer();
}
Exemplo n.º 5
0
void CTypeAFinesse::Init()
{
	// call base class
//	CFinesse::Init();

	// check the enemy and location
	m_nTarget = (m_nEndingHand == CFinesse::IN_DUMMY)? AGAINST_LHO: AGAINST_RHO;
	if (m_nTarget == AGAINST_LHO)
		m_nTargetPos = GetNextPlayer(m_nPlayerPosition);
	else
		m_nTargetPos = GetPrevPlayer(m_nPlayerPosition);

	// the ending hand is the target hand (opposite of default)
	m_nStartingHand = m_nEndingHand = m_nTargetHand;
}
Exemplo n.º 6
0
CTeamPlayer* CTeam::GetPlayer(uint32 dwPlayerID)
{
	// Look for this player...

	CTeamPlayer* pPlayer = GetFirstPlayer();

	while (pPlayer)
	{
		if (pPlayer->GetID() == dwPlayerID)
		{
			return(pPlayer);
		}

		pPlayer = GetNextPlayer(pPlayer);
	}


	// If we get here, this player is not in the team...

	return(NULL);
}
Exemplo n.º 7
0
bool CRCrack3::TranslateGvp(byte &byChair, byte &byChair1, byte &byType, byte &byRspType, byte &byGrade, byte &byCount)
{
	if (byType == TYPE_CHA)
	{
		byChair = GetNextPlayer(byChair1);
		byType = TYPE_SINGLE;

		//做点手脚
		if (m_nDepth == 1)
		{
			m_pRAction[0]->byType = TYPE_SINGLE;
			m_bGvpTag = true;
		}
		return true;
	}
	if (byType == TYPE_GOU)
	{
		if (m_pRPlayer[byChair1]->IsAlive())
			byChair = byChair1;
		else
		{
			byChair = byChair1 ^ 0x02; //对家接出牌权
			byChair1 = byChair;
		}
		byType = TYPE_GVP;
		byRspType = TYPE_GVP;

		//做点手脚
		if (m_nDepth == 1)
		{
			m_pRAction[0]->byType = TYPE_SINGLE;
			m_bGvpTag = true;
		}
		return true;
	}
	return false;
}
Exemplo n.º 8
0
void Engine::Play( void )
{
    m_pCurrentPlayer = GetFirstPlayer();

    try
    {
        while( !IsGameOver() )
        {
            m_pCurrentPlayer->PlayTurn();
            if( m_OutpostFlag )
            {
                // do not increment the pPlayer pointer;
            }
            else
            {
                m_pCurrentPlayer = GetNextPlayer( m_pCurrentPlayer );
            }
        }
    }
    catch( std::wstring* errorString )
    {
        std::wcout << L"Exception raised: " << errorString << L"\n";
    }
}
Exemplo n.º 9
0
void CGameReviewDialog::OnNext() 
{
	if (m_nPlayRound >= m_numTricksAvailable)
		return;

	// get the game record
	CGameRecord* pGameRecord = pDOC->GetGameRecord(m_nGameIndex);
	pMAINFRAME->ClearStatusMessage();

	// and show the next trick -- this is a bit tricky
	// first clear previous trick if appropriate
	// play round = # of rounds played so far
	if (m_nPlayRound > 0)
	{
		if (pDOC->GetNumCardsPlayedInRound() == 4)
		{
			pVIEW->ClearTable();
			pDOC->ClearTrick();
		}
		else
		{
			// play record ended prematurely
			pVIEW->ClearPartialTrickCards();
		}
	}

	// see if we've come to the end of hand or end of play record
	if (m_nPlayRound == 13)
	{
		// done with hand
		pMAINFRAME->SetStatusMessage("End of play record.");
		return;
	}
	else if (m_nPlayRound >= m_numTricksAvailable)
	{
		pMAINFRAME->SetStatusMessage("End of play record.");
		return;
	}

	//	
	int nPos = pGameRecord->m_nRoundLead[m_nPlayRound];
	int nPosInPlay = m_nPlayIndex % 4;
	for(int i=0;i<4;i++)
	{
		//
		m_nPlayerPosition = nPos;
		int nCardPlayed = pGameRecord->m_nGameTrick[m_nPlayRound][m_nPlayerPosition];
		CCard* pCard = deck.GetSortedCard(nCardPlayed);
		if (!pCard)
		{
			AfxMessageBox("Invalid Play Record!");
			GetDlgItem(IDC_NEXT)->EnableWindow(FALSE);
			GetDlgItem(IDC_LAST)->EnableWindow(FALSE);
			return;
		}

		// sanity check
		ASSERT(PLAYER(m_nPlayerPosition).HasCard(pCard));

		// see if we should expose dummy here
		if ((m_nPlayRound == 0) && (i == 1))
		{
			pDOC->ExposeDummy();
//			pDOC->RefreshDisplay();
		}

		//
		pVIEW->ThrowCard((Position)m_nPlayerPosition, pCard);

		// delay between cards
		if (i == 0)
			::Sleep(250);
		// NCR use the Options delays for these plays also
		if (theApp.GetValue(tbInsertPlayPause))
			::Sleep(theApp.GetValue(tnPlayPauseLength)*100);


		// advance to the next player
		nPos = GetNextPlayer(nPos);
		m_nPlayIndex++;
		if (m_nPlayIndex >= m_numPlaysAvailable)
		{
			pMAINFRAME->SetStatusMessage("End of play record.");
			break;
		}
	}

	// evaluate the trick results
	if (pDOC->GetNumCardsPlayedInRound() == 4)
		pDOC->EvaluateTrick();
	//
	pDOC->UpdatePlayHistory();

	// and update the index
	SetPlayRound(++m_nPlayRound);
}
Exemplo n.º 10
0
//---------------------------------------------------------------------------
void TFormMain::CheckOneOther(int& xMove,int& yMove) const
{
  assert(xMove == -1 && yMove == -1);
  std::vector<GameMove> moves;

  for (int y=0; y!=mMaxy; ++y)
  {
    for (int x=0; x!=mMaxx; ++x)
    {
      if (mBlocks[x][y] != NoPlayer)
      {
        if (y >= 1)
        {
          if (mBlocks[x][y-1] == NoPlayer)
          {
            GameMove move;
            move.x = x;
            move.y = y-1;
            move.anti = mBlocks[x][y];
            assert(IsValidMove(move));
            moves.push_back(move);
          }
        }
        if (y < mMaxy-1)
        {
          if (mBlocks[x][y+1] == NoPlayer)
          {
            GameMove move;
            move.x = x;
            move.y = y+1;
            move.anti = mBlocks[x][y];
            assert(IsValidMove(move));
            moves.push_back(move);
          }
        }
        if (x >= 1)
        {
          if (mBlocks[x-1][y] == NoPlayer)
          {
            GameMove move;
            move.x = x-1;
            move.y = y;
            move.anti = mBlocks[x][y];
            assert(IsValidMove(move));
            moves.push_back(move);
          }
        }
        if (x < mMaxx-1)
        {
          if (mBlocks[x+1][y] == NoPlayer)
          {
            GameMove move;
            move.x = x+1;
            move.y = y;
            move.anti = mBlocks[x][y];
            assert(IsValidMove(move));
            moves.push_back(move);
          }
        }
      }
    }
  }
  const int nMoves = moves.size();
  if (nMoves == 0) return;

  { //Get moves anti-player
    std::vector<GameMove> antiPlayerMoves;
    for (int i=0; i<nMoves; ++i)
    {
      if (IsRobot(moves[i].anti) == false) antiPlayerMoves.push_back(moves[i]);
    }
    //If there are anti-player moves, choose one at random
    if (antiPlayerMoves.empty()==false)
    {
      const int nAntiPlayerMoves = antiPlayerMoves.size();
      const int index = std::rand() % nAntiPlayerMoves;
      xMove = antiPlayerMoves[index].x;
      yMove = antiPlayerMoves[index].y;
      assert(IsValidMove(antiPlayerMoves[index]));
      return;
    }
  }
  { //Get moves anti-next-player
    std::vector<GameMove> antiNextPlayerMoves;
    for (int i=0; i<nMoves; ++i)
    {
      if (GetNextPlayer(mPlayer) == moves[i].anti) antiNextPlayerMoves.push_back(moves[i]);
    }
    //If there are anti-next-player moves, choose one at random
    if (antiNextPlayerMoves.empty()==false)
    {
      const int nAntiNextPlayerMoves = antiNextPlayerMoves.size();
      const int index = std::rand() % nAntiNextPlayerMoves;
      xMove = antiNextPlayerMoves[index].x;
      yMove = antiNextPlayerMoves[index].y;
      assert(IsValidMove(antiNextPlayerMoves[index]));
      return;
    }
  }
  //Choose a move at random
  {
    const int index = std::rand() % nMoves;
    xMove = moves[index].x;
    yMove = moves[index].y;
    assert(IsValidMove(xMove,yMove));
  }

}
Exemplo n.º 11
0
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
  //When the AI is 'thinking' no clicks are allowed
  if (IsRobot(mPlayer)==true && Sender->ClassNameIs("TTimer")==false) return;

  //ImageBuffer->Visible = false;
  const int x = X / 50;
  const int y = Y / 50;
  //Is this a relevant move?
  if (mBlocks[x][y] != NoPlayer) return;
  // Yes, a relevant move
  mBlocks[x][y] = mPlayer;
  mPlayer = GetNextPlayer(mPlayer);
  //Start the AI robot!
  if (IsRobot(mPlayer)) TimerThinker->Enabled = true;

  DrawScreen();

  //Check for three on a row
  {
    for (int y=0; y!=mMaxy; ++y)
    {
      for (int x=0; x!=mMaxx; ++x)
      {
        if (mBlocks[x][y] == NoPlayer) continue;
        EnumBlock winner = NoPlayer;
        //Horizontal
        if (x + 2 < mMaxx && mBlocks[x][y] == mBlocks[x+1][y] && mBlocks[x+1][y] == mBlocks[x+2][y])
        {
          winner = mBlocks[x][y];
        }
        //Vertical
        if (y + 2 < mMaxy && mBlocks[x][y] == mBlocks[x][y+1] && mBlocks[x][y+1] == mBlocks[x][y+2])
        {
          winner = mBlocks[x][y];
        }
        if (winner!=NoPlayer)
        {
          //A winner has been found!
          TimerDoer->Enabled = false;
          TimerThinker->Enabled = false;
          boost::scoped_ptr<TFormGewonnen> formGewonnen(
            new TFormGewonnen(0,static_cast<int>(winner),!IsRobot(winner)));
          formGewonnen->Hide();
          formGewonnen->ShowModal();
          //Show FormStoppen
          boost::scoped_ptr<TFormStoppen> formStoppen(new TFormStoppen(0));
          formStoppen->Hide();
          formStoppen->ShowModal();
          if (formStoppen->ModalResult == 1)
          { //Nog een keer
            TimerDoer->Enabled = true;
            mBlocks = std::vector<std::vector<EnumBlock> >(16, std::vector<EnumBlock>(12,NoPlayer));
            mPlayer = Player1;
            if (IsRobot(mPlayer)) TimerThinker->Enabled = true;
            DrawScreen();
          }
          else
          { //Stoppen
            ModalResult = 1;
          }


        }

      }
    }
  }
}
Exemplo n.º 12
0
void CTeam::SortPlayers(int nSortKey, int nDir)
{
	// Sanity checks...

	if (nSortKey == TM_KEY_SCORE) return;
	if (GetNumPlayers() <= 1) return;


	// Remove each player from our list, and insert it, sorted, into a temp list...

	CTeamPlayerList lsTemp;

	CTeamPlayer* pCurPlr = GetFirstPlayer();

	while (pCurPlr)
	{
		CTeamPlayer* pNextPlr = GetNextPlayer(pCurPlr);

		m_lsPlayers.Delete(pCurPlr);


		// Insert the player from our main list, sorted, into our temp list...

		CTeamPlayer* pTmpPlr = lsTemp.GetFirst();

		if (!pTmpPlr)
		{
			lsTemp.Insert(pCurPlr);
		}
		else
		{
			while (pTmpPlr)
			{
				if (nDir == TM_SORT_DESCENDING && IsGreater(pCurPlr, pTmpPlr, nSortKey))
				{
					lsTemp.InsertBefore(pTmpPlr, pCurPlr);
					pTmpPlr = NULL;
				}
				else if (nDir == TM_SORT_ASCENDING && IsLess(pCurPlr, pTmpPlr, nSortKey))
				{
					lsTemp.InsertBefore(pTmpPlr, pCurPlr);
					pTmpPlr = NULL;
				}
				else
				{
					pTmpPlr = pTmpPlr->GetNext();
					if (!pTmpPlr)
					{
						lsTemp.InsertLast(pCurPlr);
					}
				}
			}
		}

		pCurPlr = pNextPlr;
	}


	// Re-insert all items into our main list...

	CTeamPlayer* pPlr = lsTemp.GetFirst();

	while (pPlr)
	{
		CTeamPlayer* pNextPlr = pPlr->GetNext();
		m_lsPlayers.InsertLast(pPlr);
		pPlr = pNextPlr;
	}
}
Exemplo n.º 13
0
//
// AssignCardsPBN()
//
void CEasyBDoc::AssignCardsPBN(const CString& str)
{
	CString strHoldings = str;
	strHoldings.TrimLeft();

	// get the starting player
	int nPlayer = CharToPosition(strHoldings[0]);
	strHoldings = strHoldings.Mid(2);	// go past the "X:" mark
	strHoldings.TrimLeft();

	// read in the holdings string
	int nIndex;
	for(int i=0;i<4;i++)
	{
		int numCards = 0;
		// read in each suit
		for(int nSuit=SPADES;nSuit>=CLUBS;nSuit--)
		{
			if (i < 3)
			{
				// first 3 players
				if (nSuit != CLUBS)
					nIndex = strHoldings.Find('.');
				else
					nIndex = strHoldings.Find(' ');
			}
			else
			{
				// last player
				if (nSuit != CLUBS)
					nIndex = strHoldings.Find('.');
				else
					nIndex = strHoldings.GetLength();

			}
			CString strSuit = strHoldings.Left(nIndex);
			strSuit.TrimLeft();
			// check for end of string
			if (strSuit == _T("."))
				strSuit = _T("");
			//
			for(int j=0;j<strSuit.GetLength();j++)
			{
				int nValue = CharToFaceValue(strSuit[j]);
				int nIndex = MAKEDECKVALUE(nSuit, nValue);
				CCard* pCard = deck.GetSortedCard(nIndex);
				ASSERT(pCard);
				m_pPlayer[nPlayer]->AddCardToHand(pCard,FALSE);
				m_pPlayer[nPlayer]->AddCardToInitialHand(pCard);
				numCards++;
			}
			// move to the next suit
			if (strHoldings.GetLength() > nIndex+1)
				strHoldings = strHoldings.Mid(nIndex+1);
			else
				strHoldings = strHoldings.Mid(nIndex);
		}
		// verify
		if (numCards != 13)
		{
			ClearAllInfo();
			pVIEW->Notify(WM_COMMAND, WMS_REFRESH_DISPLAY);
			AfxMessageBox("Invalid deal string!");
			AfxThrowFileException(CFileException::generic);
		}
		//
		nPlayer = GetNextPlayer(nPlayer);
	}
	//
	m_bHandsDealt = TRUE;
}
Exemplo n.º 14
0
BOOL CEasyBDoc::ExportGameInfo(CArchive& ar) 
{
	// export game info
	// export hands
	WriteText(ar, "[Dealt Hands]\r\n");
	CString strHands = FormatOriginalHands();
	WriteText(ar, strHands);

	// export bidding history
	WriteText(ar, "\r\n\r\n");
	WriteText(ar, "[Bidding History]\r\n");
	const CString strBiddingHistory = pMAINFRAME->GetBiddingHistory();
	WriteText(ar, strBiddingHistory);
	if (ISBID(GetContract()))
	{
		int nDeclarer = GetDeclarerPosition();
		CString strContract = FormString("Contract: %s by %s; %s leads", pDOC->GetContractString(), PositionToString(nDeclarer), PositionToString(GetNextPlayer(nDeclarer)));
//		WriteText(pFile, strContract);
	}

	// export play history
	WriteText(ar, "\r\n\r\n\r\n");
	WriteText(ar, "[Play History]\r\n");
	const CString strPlayHistory = pMAINFRAME->GetPlayHistory();
	WriteText(ar, strPlayHistory);

	// export current hands
	if (GetNumTricksPlayed() > 0)
	{
		WriteText(ar, "\r\n\r\n\r\n");
		WriteText(ar, "[Current Hands]\r\n");
		CString strHands = pDOC->FormatCurrentHands();
		WriteText(ar, strHands);
	}

	// done
	ar.Flush();
	return TRUE;
}
Exemplo n.º 15
0
void CGameReviewDialog::OnLast() 
{
	// fast forward to the end
	if (m_nPlayRound >= m_numTricksAvailable)
		return;

	// show wait cursor
	CWaitCursor wait;
//	pMAINFRAME->SetStatusMessage(_T("Advancing to the end of the play record..."));

	// get the game record
	CGameRecord* pGameRecord = pDOC->GetGameRecord(m_nGameIndex);
	pMAINFRAME->ClearStatusMessage();

	// first clear previous trick if appropriate
	if (m_nPlayRound > 0)
	{
		if (pDOC->GetNumCardsPlayedInRound() == 4)
		{
			pVIEW->ClearTable();
			pDOC->ClearTrick();
		}
		else
		{
			// play record ended prematurely
			pVIEW->ClearPartialTrickCards();
		}
	}

	// see if we've come to the end of hand or end of play record
	while (m_nPlayRound < m_numTricksAvailable)
	{
		//	
		int nPos = pGameRecord->m_nRoundLead[m_nPlayRound];
		int nPosInPlay = m_nPlayIndex % 4;
		for(int i=0;i<4;i++)
		{
			//
			m_nPlayerPosition = nPos;
			int nCardPlayed = pGameRecord->m_nGameTrick[m_nPlayRound][m_nPlayerPosition];
			CCard* pCard = deck.GetSortedCard(nCardPlayed);
			if (!pCard)
			{
				AfxMessageBox("Invalid Play Record!");
				GetDlgItem(IDC_NEXT)->EnableWindow(FALSE);
				GetDlgItem(IDC_LAST)->EnableWindow(FALSE);
				return;
			}

			// sanity check
			ASSERT(PLAYER(m_nPlayerPosition).HasCard(pCard));

			// see if we should expose dummy here
			if ((m_nPlayRound == 0) && (i == 1))
			{
				PLAYER(pDOC->GetDummyPosition()).SetDummyFlag(TRUE);
				pDOC->ExposeDummy();
			}

			// play the card
			pDOC->EnterCardPlay((Position)nPos, pCard);

			// if this is the last round, show the card
			if (m_nPlayRound == m_numTricksAvailable-1)
				pVIEW->DrawPlayedCard((Position)nPos, pCard, FALSE);

			// advance to the next player
			nPos = GetNextPlayer(nPos);
			m_nPlayIndex++;
			if (m_nPlayIndex >= m_numPlaysAvailable)
				break;
		}

		// evaluate the trick results
		if (pDOC->GetNumCardsPlayedInRound() == 4)
		{
			pDOC->EvaluateTrick(TRUE);
			// but don't clear the final trick; leave it to show
			if (m_nPlayIndex < m_numPlaysAvailable)
				pDOC->ClearTrick();
		}
		//
		m_nPlayRound++;
		if (m_nPlayIndex >= m_numPlaysAvailable)
			break;
	}

	// update status
	pDOC->ResetDisplay();
	pVIEW->DisplayTricks();
	pDOC->UpdatePlayHistory();
	pMAINFRAME->SetStatusMessage("End of play record.");
	SetPlayRound(m_nPlayRound);
}
Exemplo n.º 16
0
//
// ParsePlaysPBN()
//
int CEasyBDoc::ParsePlaysPBN(CArchive& ar, const CString& strValue)
{
	CString string, partString;

	// read in the rest of the plays
	int nExitCode = 0;
	BOOL bCommentStarted = FALSE;
	for(;;) 
	{
		if (m_nLineNumber >= numLines)
			break;
		partString = strLines.GetAt(m_nLineNumber++);
		if ( (!partString.IsEmpty() && 
			 ((partString[0] == '[') || (partString.Find('*') >= 0)))
			 || partString.IsEmpty() )  // NCR allow empty string to end this section
			break;
		string += partString + " ";
	}

	// check if we read up to the next tag, or are at the end of the game record
	if (partString.IsEmpty() || (partString[0] == '['))
	{
		strBuf = partString;
		if (m_nLineNumber < numLines)
			m_nLineNumber--;
	}

	// and process
	int nEnd, nRoundWinner;
	int nOffset = 0;
	int nPlayIndex = 0;
	int nRound = 0;
	int nLen = string.GetLength();
	//
	int nStartingPos = CharToPosition(strValue[0]);
	pGameRecord->m_nRoundLead[0] = nStartingPos;
	pGameRecord->m_numCardsPlayed = 0;

	//
	for(;;) 
	{
		// skip leading spaces
		while((nOffset < nLen) && (string[nOffset] == ' '))
			nOffset++;
		if (nOffset < nLen) 
		{
			// grab the next chunk
			nEnd = string.Mid(nOffset).Find(' ');
			if (nEnd < 0)
				nEnd = nLen;
			partString = string.Mid(nOffset, nEnd);
			nOffset += nEnd + 1;
			if (partString[0] == '=')
			{
				// this is a note reference
				int nRef = atoi(partString.Mid(1));
				pGameRecord->m_mapPlayNotes.SetAt(nPlayIndex, nRef);
			}
			else if (partString[0] == '-')
			{
				// this is a blank play
				nPlayIndex++;
			}
			else if (partString[0] == '$')
			{
				// this is a NAG -- ignore it
			}
			else
			{
				// this is a play, so record it
				int nCardVal = ::StringToDeckValue(partString);
				int nPos = nStartingPos;
				int nPosOffset = nPlayIndex % 4;
				for(int i=0;i<nPosOffset;i++)
					nPos = GetNextPlayer(nPos);
				//
				pGameRecord->m_nGameTrick[nRound][nPos] = nCardVal;
				pGameRecord->m_nPlayRecord[nPlayIndex] = nCardVal;
				nPlayIndex++;
				pGameRecord->m_numCardsPlayed++;
				// if a round is finished, record the round winner
				if (((nPlayIndex) % 4) == 0)
				{
					nRoundWinner = pGameRecord->DetermineRoundWinner(nRound);
					pGameRecord->m_nRoundLead[++nRound] = nRoundWinner;
				}
			}
		}
		else
		{
			return nExitCode;
		}
	}
}
Exemplo n.º 17
0
//
//---------------------------------------------------------
//
// PBN File output routine
//
BOOL CEasyBDoc::WriteFilePBN(CArchive& ar) 
{
	pFile = ar.GetFile();
	ASSERT(pFile != NULL);

	// write header
	WriteComment("");
	WriteComment("EXPORT");
	WriteComment("PBN Format 1.0");
	WriteComment(FormString("File generated by Easy Bridge version %s", theApp.GetProgramVersionString()));
	WriteComment("");

	//
	// write the data
	//

	// Event tag
	WriteLine(TAG_EVENT, FormString("%s Game", theApp.GetValue(tstrProgramTitle)));

	// Site Tag
	WriteLine(TAG_SITE, "At Home"); // NCR added At Home

	// Date Tag
	CTime time = CTime::GetCurrentTime();
	WriteLine(TAG_DATE, time.Format("%Y.%m.%d"));

/*
 * skip the round tag -- no longer mandatory in PBN 0.91+
 *
	// Round Tag
	WriteLine(TAG_ROUND, "");
 */

	// Board Tag
	WriteLine(TAG_BOARD, "1"); // NCR added 1

	// West/North/East/South Tags
	WriteLine(TAG_WEST, "Computer");
	WriteLine(TAG_NORTH, "Computer");
	WriteLine(TAG_EAST, "Computer");
	WriteLine(TAG_SOUTH, "Human Player");

	// Dealer Tag
	WriteLine(TAG_DEALER, FormString("%c", PositionToChar(m_nDealer)));

	// Vulnerable Tag
	CString strVulnerable;
	if ((m_bVulnerable[NORTH_SOUTH]) && (m_bVulnerable[EAST_WEST]))
		strVulnerable = "Both";
	else if (m_bVulnerable[NORTH_SOUTH])
		strVulnerable = "NS";
	else if (m_bVulnerable[EAST_WEST])
		strVulnerable = "EW";
	else
		strVulnerable = "None";
	WriteLine(TAG_VULNERABLE, strVulnerable);

	// deal tag
	CString strDeal = "W:";
	int nPos = WEST;
	int i; // NCR-FFS added here, removed below
	for(/*int*/ i=0;i<4;i++)
	{
		CCardHoldings& cards = m_pPlayer[nPos]->GetHand().GetInitialHand();
		strDeal += cards.GetGIBFormatHoldingsString();
		nPos = GetNextPlayer(nPos);
		if (i < 3)
			strDeal += ' ';
	}
	WriteLine(TAG_DEAL, strDeal);

	// Scoring tag
	if (theApp.IsRubberInProgress())
		WriteLine(TAG_SCORING, _T("Rubber"));
	else
		WriteLine(TAG_SCORING, _T("None"));

	// Declarer Tag
	if (ISPOSITION(m_nDeclarer))
		WriteLine(TAG_DECLARER, FormString("%c", PositionToChar(m_nDeclarer)));
	else
		WriteLine(TAG_DECLARER, "?");

	// Contract Tag
	if (ISBID(m_nContract)) 
	{
		// NCR Include ContractToString() here as PBN file does NOT have space before X
		CString strBid;
		strBid.Format("%d%s", 
					  BID_LEVEL(m_nContract), 
					  szSuitNameShort[BID_SUIT(m_nContract)]);
		int nModifier = pDOC->GetContractModifier();
		if (nModifier > 0)
			strBid += FormString("%s", ((nModifier == 1)? "X" : "XX")); // w/o space

		WriteLine(TAG_CONTRACT, strBid);  // NCR replaced ContractToString(m_nContract)
	}
	else
		WriteLine(TAG_CONTRACT, "?");

	// Result tag
	if (m_numTricksPlayed == 13)
		WriteLine(TAG_RESULT, FormString("%d", m_numTricksWon[m_nContractTeam])); // NCR removed extra "s
	else
		WriteLine(TAG_RESULT, "?");

	//
	// write out the hands in comment form
	//
	CString strHands = "{\r\n" + pDOC->FormatOriginalHands() + "}";
	WriteLine(strHands);

	//
	// write out auction
	//
	CString strBids = FormString("[Auction \"%c\"]", PositionToChar(m_nDealer)); // NCR Lowercased
	if (m_numBidsMade > 0)
		strBids += "\r\n";
	nPos = m_nDealer;
	for(i=0;i<m_numBidsMade;i++)
	{
		strBids += FormString("%s ", ::BidToPBNString(m_nBiddingHistory[i]));
		nPos = ::GetNextPlayer(nPos);
		if ( (((i+1) % 4) == 0) && (i < m_numBidsMade-1) )
			strBids += "\r\n";
	}
	// add marker if needed
	if (!ISBID(m_nContract))
		strBids += "\r\n*";
	// and write out
	WriteLine(strBids);


	//
	// write out plays
	//
	CString strPlays = FormString("[Play \"%c\"]", PositionToChar(m_nGameLead));  // NCR Lowercased
	if (m_numTricksPlayed> 0)
		strPlays += "\r\n";
	bool bLastRowFnd = false;  // NCR added - only output single row with -s
	for(i=0;i<m_numTricksPlayed;i++)
	{
		int nPos = m_nGameLead;
		for(int j=0;j<4;j++)
		{
			CCard* pCard = m_pGameTrick[i][nPos];
			if (pCard == NULL) {
				strPlays += "-  ";
				bLastRowFnd = true;  // NCR this row will end the output
			}
			else
				strPlays += FormString("%s ", pCard->GetName());
			nPos = ::GetNextPlayer(nPos);
		} // end for(j) thru poisitions
		if (i < m_numTricksPlayed-1)
			strPlays += "\r\n";
		if(bLastRowFnd)
			break;  // NCR finished output plays on line with -s
	} // end for(i) thru tricks
	// add marker if needed
	if (m_numTricksPlayed < 13)
		strPlays += "\r\n*";
	// and write out
	WriteLine(strPlays);


	// Generator Tag
	WriteLine(TAG_GENERATOR, FormString("Easy Bridge version %s", theApp.GetProgramVersionString()));

	// Description Tag
	WriteLine(TAG_DESCRIPTION, m_strFileDescription);

	// blank line
//	SkipLine();

	//
	// write out the auction
	//

	//	
	// All done
	//
	ar.Flush();
	return TRUE;
}
Exemplo n.º 18
0
//
//---------------------------------------------------------
//
BOOL CEasyBDoc::ReadFile(CArchive& ar) 
{
	int i,nRtnCode,nLineCode,nSectionCode;
	int	nIndex,nValue,nOffset,nLen;
	int nPlayOffset, nPos;
	int nBidIndex = 0;
	CString strMessage,string,partString;
	CCard* pCard;
	double fValue;
	BOOL bValue;
	BOOL bFileInfoFound = FALSE;

	
	// read
	m_nLineNumber = 0;
	try
	{
		for(;;) 
		{

			nRtnCode = ReadLine(ar, strBuf);
next:		if (nRtnCode == EOF)
				break;
			if (nRtnCode == 0)
				continue;
			if ((strBuf[0] == '#') || (strBuf[0] == '*'))
				continue;
			nLineLen = nRtnCode;
			nLineCode = ParseLine(strBuf,nLineLen);
			
			if (nLineCode < 0) 
			{

				// section signifier
				nSectionCode = -nLineCode;
				if (nSectionCode == BLOCK_FILEINFO)
				{
					//
					bFileInfoFound = TRUE;
					// file info; skip this section
					do {
						nRtnCode = ReadLine(ar, strBuf);
					} while ((nRtnCode != EOF) && (strBuf.Left(2) != "[["));
					//
					goto next;
				} 
				//
				if (nSectionCode == BLOCK_FILEDESC) 
				{
					// file description; read until next block
					m_strFileDescription.Empty();
					do {
						nRtnCode = ReadLine(ar, strBuf);
						if (strBuf.Left(2) != "[[")
						{
							strBuf += "\r\n";
							m_strFileDescription += strBuf;
						}
					} while ((nRtnCode != EOF) && (strBuf.Left(2) != "[["));

					// trim ending CR/LF
					int nLen = m_strFileDescription.GetLength();
					if ((nLen >= 2) && (m_strFileDescription[nLen-1] == _T('\n')))
						m_strFileDescription = m_strFileDescription.Left(nLen-2);
					//
					goto next;
				} 
				else if (nSectionCode == BLOCK_COMMENTS) 
				{
					// file comments
					for (;;) 
					{
						nRtnCode = ReadLine(ar, strBuf);
						if ((nRtnCode == EOF) || (strBuf.Left(2) == "[[")) 
						{
							// update file comments dialog if it's open
							CWnd* pWnd = pMAINFRAME->GetDialog(twFileCommentsDialog);
							if (pWnd)
								pWnd->SendMessage(WM_COMMAND, WMS_UPDATE_TEXT, FALSE);
							goto next;
						}
						strBuf += "\r\n";
						m_strFileComments += strBuf;
					}
				}
				else if ((nSectionCode == BLOCK_SOUTH_ANALYSIS) ||
						 (nSectionCode == BLOCK_WEST_ANALYSIS) ||
						 (nSectionCode == BLOCK_NORTH_ANALYSIS) ||
						 (nSectionCode == BLOCK_EAST_ANALYSIS))
				{
					// don't bother to save the analysis
					int nPlayer = nSectionCode - BLOCK_SOUTH_ANALYSIS;
					CString strAnalysisBiffer;
					do {
						nRtnCode = ReadLine(ar, strBuf);
	//					strBuf += "\r\n";
	//					strAnalysisBiffer += strBuf;
					} while ((nRtnCode != EOF) && (strBuf.Left(2) != "[["));
	//				m_player[nPlayer].SetValueString(tszAnalysis,  strAnalysisBiffer);
					goto next;
				}

			} 
			else if (nLineCode > 0) 
			{

				// first skip spaces
				nLen = strBuf.GetLength();
				while ((nDataPosition < nLen) && 
						(strBuf[nDataPosition] == ' '))
					nDataPosition++;
				if (nDataPosition >= nLen)
					continue;
				// then get data item
				string = strBuf.Mid(nDataPosition);
				nValue = atoi(string);
				fValue = atof(string);
				if ((string == "Yes") || (string == "1"))
					bValue = TRUE;
				else
					bValue = FALSE;

				switch(nLineCode) 
				{

					case ITEM_PROGRAM_ID:
						m_strFileProgTitle = string;
						break;

					case ITEM_MAJOR_VERSIONNO:
						m_nFileProgMajorVersion = nValue;
						break;

					case ITEM_MINOR_VERSIONNO:
						m_nFileProgMinorVersion = nValue;
						break;

					case ITEM_INCREMENT_VERSIONNO:
						m_nFileProgIncrementVersion = nValue;
						break;

					case ITEM_BUILD_NUMBER:
						m_nFileProgBuildNumber = nValue;
						break;

					case ITEM_BUILD_DATE:
						m_strFileProgBuildDate = string;
						break;

					case ITEM_FILE_DATE:
						m_strFileDate = string;
						break;

					// hand info, 10..19
					case ITEM_CURRHAND_NORTH:
						AssignCards(string,NORTH);
						break;

					case ITEM_CURRHAND_EAST:
						AssignCards(string,EAST);
						break;

					case ITEM_CURRHAND_SOUTH:
						AssignCards(string,SOUTH);
						break;

					case ITEM_CURRHAND_WEST:
						AssignCards(string,WEST);
						break;

					case ITEM_ORIGHAND_NORTH:
						AssignCards(string,NORTH,TRUE);
						break;

					case ITEM_ORIGHAND_EAST:
						AssignCards(string,EAST,TRUE);
						break;

					case ITEM_ORIGHAND_SOUTH:
						AssignCards(string,SOUTH,TRUE);
						break;

					case ITEM_ORIGHAND_WEST:
						AssignCards(string,WEST,TRUE);
						break;

					// current round info
					case ITEM_CURR_ROUND_LEAD:
						m_nRoundLead = StringToPosition(string);
						break;

					case ITEM_NUM_CARDS_PLAYED_IN_ROUND:
						m_numCardsPlayedInRound = nValue;
						break;

					case ITEM_TRICK_CARD_1:
						m_pCurrTrick[0] = deck.GetCard(string);
						break;

					case ITEM_TRICK_CARD_2:
						m_pCurrTrick[1] = deck.GetCard(string);
						break;

					case ITEM_TRICK_CARD_3:
						m_pCurrTrick[2] = deck.GetCard(string);
						break;

					case ITEM_TRICK_CARD_4:
						m_pCurrTrick[3] = deck.GetCard(string);
						break;

					// game status info
					case ITEM_VIEW_STATUS_CODE:
						pVIEW->SetCurrentMode((CEasyBView::ScreenMode)nValue);
						break;

					case ITEM_RUBBER_IN_PROGRESS:
						theApp.SetValue(tbRubberInProgress, bValue);
						break;

					case ITEM_GAME_IN_PROGRESS:
						// TEMP
//						theApp.SetValue(tbGameInProgress, FALSE);
						theApp.SetValue(tbGameInProgress, bValue);
						break;

					case ITEM_BIDDING_IN_PROGRESS:
						theApp.SetValue(tbBiddingInProgress, bValue);
						break;

					case ITEM_HANDS_DEALT:
						m_bHandsDealt = bValue;
						break;
					
					case ITEM_CONTRACT_SUIT:
						nLen = string.GetLength();
						m_nContractSuit = CharToSuit(string.GetAt(0));
						break;

					case ITEM_CONTRACT_LEVEL:
						m_nContractLevel = nValue;
						break;

					case ITEM_CONTRACT_MODIFIER:
						switch(nValue) 
						{
							case 0:
								m_bDoubled = FALSE;
								m_bRedoubled = FALSE;
								m_nContractModifier = 0;
								break;
							case 1:
								m_bDoubled = TRUE;
								m_bRedoubled = FALSE;
								m_nContractModifier = 1;
								break;
							case 2:
								m_bDoubled = FALSE;
								m_bRedoubled = TRUE;
								m_nContractModifier = 2;
								break;
						}
						break;

					case ITEM_DEALER:
						m_nDealer = StringToPosition(string);
						break;

					case ITEM_NUM_BIDS:
//						m_numBidsMade = nValue;
						break;

					case ITEM_BIDDING_HISTORY:
						strBiddingHistory = string;
						break;

					case ITEM_DECLARER:
						m_nDeclarer = StringToPosition(string);
						m_nContractTeam = GetPlayerTeam(m_nDeclarer);
						m_nDefendingTeam = (m_nContractTeam == NORTH_SOUTH)? EAST_WEST : NORTH_SOUTH;
						break;

					// game record
					case ITEM_NUM_TRICKS_PLAYED:
						m_numTricksPlayed = nValue;
						break;

					case ITEM_NUM_TRICKS_WON_NS:
						m_numTricksWon[0] = nValue;
						break;

					case ITEM_NUM_TRICKS_WON_EW:
						m_numTricksWon[1] = nValue;
						break;

					case ITEM_GAME_LEAD:
						m_nGameLead = StringToPosition(string);
						break;

					case ITEM_GAME_TRICK_1: case ITEM_GAME_TRICK_2: 
					case ITEM_GAME_TRICK_3: case ITEM_GAME_TRICK_4: 
					case ITEM_GAME_TRICK_5: case ITEM_GAME_TRICK_6: 
					case ITEM_GAME_TRICK_7: case ITEM_GAME_TRICK_8: 
					case ITEM_GAME_TRICK_9: case ITEM_GAME_TRICK_10: 
					case ITEM_GAME_TRICK_11: case ITEM_GAME_TRICK_12: 
					case ITEM_GAME_TRICK_13:
						try
						{
							nIndex = nLineCode - ITEM_GAME_TRICK_1;
							nOffset = 0;
							nLen = string.GetLength();
							// first read the lead player for the trick
							partString = string.Mid(nOffset);
							m_nTrickLead[nIndex] = StringToPosition(partString);
							nOffset = string.Find(' ');
							//
							for(i=0;i<4;i++) 
							{
								while((nOffset < nLen) && (string[nOffset] == ' '))
									nOffset++;
								partString = string.Mid(nOffset);
								nOffset += 2;
								if (partString.IsEmpty()) 
								{
									strMessage.Format("Incomplete Trick record at line %d;\n%s",
													  m_nLineNumber, string);
									AfxMessageBox(strMessage);
									break;
								}
								//
								if (partString.Left(2) == "--")
								{
									m_pGameTrick[nIndex][i] = NULL;
								}
								else
								{
									pCard = deck.GetCard(partString);
									m_pGameTrick[nIndex][i] = pCard;
								}
							}
							// insert the trick record into the game record
							// in the proper order
							nPlayOffset = nIndex * 4;
							nPos = m_nTrickLead[nIndex];
							for(i=0;i<4;i++)
							{
								CCard* pCard = m_pGameTrick[nIndex][nPos];
								if (pCard)
									m_nPlayRecord[nPlayOffset+i] = pCard->GetDeckValue();
								nPos = GetNextPlayer(nPos);
							}
							// and finally read the trick's winner 
							while((nOffset < nLen) && (string[nOffset] == ' '))
								nOffset++;
							partString = string.Mid(nOffset);
							m_nTrickWinner[nIndex] = StringToPosition(partString);
						}
						catch(...)
						{
							// error
						}
						break;

					// match info
					case ITEM_SCORE_NS_BONUS:
						m_nBonusScore[NORTH_SOUTH] = nValue;
						break;

					case ITEM_SCORE_NS_GAME0:
						m_nGameScore[0][NORTH_SOUTH] = nValue;
						break;

					case ITEM_SCORE_NS_GAME1:
						m_nGameScore[1][NORTH_SOUTH] = nValue;
						break;

					case ITEM_SCORE_NS_GAME2:
						m_nGameScore[2][NORTH_SOUTH] = nValue;
						break;

					case ITEM_SCORE_NS_GAMES_WON:
						m_numGamesWon[NORTH_SOUTH] = nValue;
						break;

					case ITEM_SCORE_EW_BONUS:
						m_nBonusScore[EAST_WEST] = nValue;
						break;

					case ITEM_SCORE_EW_GAME0:
						m_nGameScore[0][EAST_WEST] = nValue;
						break;

					case ITEM_SCORE_EW_GAME1:
						m_nGameScore[1][EAST_WEST] = nValue;
						break;

					case ITEM_SCORE_EW_GAME2:
						m_nGameScore[2][EAST_WEST] = nValue;
						break;

					case ITEM_SCORE_EW_GAMES_WON:
						m_numGamesWon[EAST_WEST] = nValue;
						break;

					case ITEM_CURRENT_GAME_INDEX:
						m_nCurrGame = nValue-1;
						break;

					case ITEM_BONUS_SCORE_RECORD:
						m_strArrayBonusPointsRecord.Add(StripQuotes(string));
						break;

					case ITEM_GAME_SCORE_RECORD:
						m_strArrayTrickPointsRecord.Add(StripQuotes(string));
						break;

					// misc info
					case ITEM_AUTOSHOW_COMMENTS:
						m_bShowCommentsUponOpen = bValue;
						break;
					case ITEM_AUTOSHOW_BID_HISTORY:
						m_bShowBidHistoryUponOpen = bValue;
						break;
					case ITEM_AUTOSHOW_PLAY_HISTORY:
						m_bShowPlayHistoryUponOpen = bValue;
						break;
					case ITEM_AUTOSHOW_ANALYSES:
						m_bShowAnalysesUponOpen = bValue;
						break;

				}

			} 
			else 
			{

	/*
				// unknown line
				strMessage.Format("Found Unknown line\n%s.\nContinue?",strBuf);
				if (AfxMessageBox(strMessage, MB_ICONEXCLAMATION | MB_OKCANCEL) == IDCANCEL)
					break;
	*/
			}

		}
	}
	catch(...)
	{
		// handle any improper file error here
		ClearAllInfo();
//		AfxMessageBox("An error ocurred while reading the game file.");
		return FALSE;
	}

	// see if this was a valid file
	if (!bFileInfoFound)
	{
		AfxMessageBox("This is not a proper Easy Bridge game file.");
		AfxThrowFileException(CFileException::generic);
	}

	//
	// do some sanity checks
	//
	m_nContract = MAKEBID(m_nContractSuit, m_nContractLevel);
	if (!ISPLAYER(m_nDeclarer) || !ISBID(m_nContract))
		theApp.SetValue(tbGameInProgress, FALSE);

	//
	// parse the bidding history
	//
	if (!ISPLAYER(m_nDeclarer))
		m_nDeclarer = SOUTH;
	nPos = m_nDeclarer;
	m_nCurrPlayer = nPos;
	int nTeam = GetPlayerTeam(nPos);
	nOffset = 0;
	// 
	nLen = strBiddingHistory.GetLength();
	for(i=0;;i++) 
	{
		// skip leading spaces
		while((nOffset < nLen) && (strBiddingHistory[nOffset] == ' '))
			nOffset++;
		if (nOffset >= nLen)
			break;
		// grab the next bid
		partString = strBiddingHistory.Mid(nOffset);
		int nBid = ContractStringToBid(partString);
		// and record it
		m_nBiddingHistory[m_numBidsMade] = nBid;
		m_numBidsMade++;
		m_nCurrPlayer = GetNextPlayer(m_nCurrPlayer);
		int nBiddingRound = i % 4;
		m_nBidsByPlayer[nPos][nBiddingRound] = nBid;
		// see if this is an actual numeric bid
		if (ISBID(nBid))
		{
			m_nValidBidHistory[m_numValidBidsMade] = nBid;
			m_numValidBidsMade++;
			m_nLastValidBid = nBid;
			m_nLastValidBidTeam = nTeam;
		}
		// skip over remainder of current bid string
		while((nOffset < nLen) && (strBiddingHistory[nOffset] != ' '))
			nOffset++;
		// and move to the next player
		nPos = GetNextPlayer(nPos);
		nTeam = GetOpposingTeam(nTeam);
	}
	if (ISBID(m_nContract))
		UpdateBiddingHistory();


	// tally some figures
	m_nTotalScore[0] = m_nGameScore[0][0] + m_nGameScore[1][0] +
					   m_nGameScore[2][0] + m_nBonusScore[0];
	m_nTotalScore[1] = m_nGameScore[0][1] + m_nGameScore[1][1] +
					   m_nGameScore[2][1] + m_nBonusScore[1];

	// vulnerability
	if ((m_numGamesWon[0] > 0) && (m_numGamesWon[1] > 0)) 
	{
		m_nVulnerableTeam = BOTH;
		m_bVulnerable[0] = m_bVulnerable[1] = TRUE;
	} 
	else if (m_numGamesWon[0] > 0) 
	{
		m_nVulnerableTeam = NORTH_SOUTH;
		m_bVulnerable[0] = TRUE;
	} 
	else if (m_numGamesWon[1] > 0)
	{
		m_nVulnerableTeam = EAST_WEST;
		m_bVulnerable[1] = TRUE;
	} 
	else 
	{
		m_nVulnerableTeam = NEITHER;
	}

	//
	// set contract info
	//
	m_nContract = ContractParamsToBid(m_nContractSuit,m_nContractLevel);
	m_nTrumpSuit = m_nContractSuit;
	m_nBiddingRound = nBidIndex;
	// set play info 
	if (ISBID(m_nContract) && ISPLAYER(m_nDeclarer))
	{
		// contract has been reached
		m_nDummy = GetPartner((int) m_nDeclarer);
		m_nGameLead = GetNextPlayer(m_nDeclarer);
		m_nRoundLead = m_nGameLead;
		m_nCurrPlayer = m_nRoundLead;
		m_nTrickLead[0] = m_nRoundLead;
//		m_pPlayer[m_nDummy]->SetDummyFlag(TRUE);
//		m_pPlayer[m_nDeclarer]->SetDeclarerFlag(TRUE);
	}
	else
	{
		// contract has NOT been reached, so restart
		m_nCurrPlayer = m_nDealer;
		m_numBidsMade = 0;
	}

	// restore initial hands (temp?)
	for(i=0;i<4;i++)
		m_pPlayer[i]->RestoreInitialHand();

	// not reviewing game
	m_bReviewingGame = FALSE;

	// all done
	return TRUE;
}
Exemplo n.º 19
0
byte CRCrack3::Crack(byte byWinBitmap, byte byChair1, byte byType, byte byRspType, byte byGrade, byte byCount, byte byScore)
{
	//破解初始化
	byte byChair = 0;
	m_nDepth = 0;
	m_bGvpTag = false;

	//保存初始状态
	SaveAction(byWinBitmap, byChair, byChair1, byType, byRspType, byGrade, byCount);

	//复原手牌位图
	for (int i = 0; i < 4; i++)
		m_pRPlayer[i]->RestoreBitmap();

	dword dwInterrupt = 0;
	while (m_nDepth < MAX_CRACK_DEPTH)
	{
		if (dwInterrupt++ >= g_dwCrackDepth) //检测中断
			return INTERRUPT;

		byRspType = m_pRPlayer[byChair]->RspCards(byType, byRspType, byGrade, byCount); //行为应答
		if (byRspType == TYPE_GVP)
		{
			//放弃操作转义
			if (TranslateGvp(byChair, byChair1, byType, byRspType, byGrade, byCount))
				continue;

			if (byType == TYPE_GVP) //无牌可出
			{
				if (m_nDepth == 1)
					return (byChair & 1) ? CONTRACT_YES : CONTRACT_FAIL;
				BackAction(byWinBitmap, byChair, byChair1, byType, byRspType, byGrade, byCount);
				continue;
			}

			//获得下一个出牌的玩家
			GetNextRspser(byChair, byChair1);

			//更新出牌类型
			if (byChair == byChair1)
				byType = TYPE_GVP;
			else
			{
				byType = m_pRAction[m_nDepth - 1]->byRspType;
				if (byType == TYPE_GVP)
					byType = m_pRAction[m_nDepth - 1]->byType;
				byGrade = m_pRAction[m_nDepth - 1]->byGrade;
				byCount = m_pRAction[m_nDepth - 1]->byCount;
			}

			if (m_nDepth == 1)
				m_bGvpTag = true;
			continue;
		}
		SaveAction(byWinBitmap, byChair, byChair1, byType, byRspType, byGrade, byCount); //保存出牌行为

		//获胜处理
		if (!m_pRPlayer[byChair]->IsAlive())
		{
			byte byContract = TranslateWin(byScore, byWinBitmap, byChair, byChair1, byType, byRspType, byGrade, byCount);
			if (byContract == CONTRACT_BKT)
				continue;
			if (byContract == CONTRACT_FAIL || byContract == CONTRACT_YES)
				return byContract;
		}

		//更新最后出牌者
		byChair1 = byChair;

		//出牌操作转义
		if (TranslatePut(byChair, byChair1, byType, byRspType, byGrade, byCount))
			continue;

		//下一个出牌者
		byChair = GetNextPlayer(byChair);
		byType = byRspType;
	}
	return CONTRACT_UNK; //无效语句
}