Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
minhkhanhhaugiang committed Jan 17, 2011
1 parent 5b4f3cb commit 4818e99
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 29 deletions.
41 changes: 36 additions & 5 deletions vcards/ChickenAI/ChickenAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,52 @@ public void OnTurnToOtherPlayer(PlayerInfo pInfo)
public void OnServerPhatBai(PackLogical pack)
{
myPack = pack;
myPack.SortByValue();
}
//List<CardCombination> listNhomBai;
//private void
public CardCombination OnTurnToMe(BuocDi buoc)
{
CardCombination cards = null;
if (buoc.LoaiBuocDi == LoaiBuocDi.BuocDau)
{
}
else if (buoc.LoaiBuocDi == LoaiBuocDi.BuocMoi)
if (buoc.LoaiBuocDi == LoaiBuocDi.BuocDau || buoc.LoaiBuocDi == LoaiBuocDi.BuocMoi)
{
CardCombination racMin = CardCombination.CreateCombination(myPack[0]);
CardCombination[] listCC = CardCombination.GetCombinationCoChua(myPack, racMin);
if (listCC != null)
{
cards = listCC[0];
foreach (CardCombination cc in listCC)
{
if (cards.CardsCount < cc.CardsCount)
{
cards = cc;
}
}
}
}
//else if (buoc.LoaiBuocDi == LoaiBuocDi.BuocMoi)
//{
//}
else
{

List<CardCombination> listCC = new List<CardCombination>();
foreach (CardLogical card in myPack.ListCards)
{
CardCombination racMin = CardCombination.CreateCombination(card);
CardCombination[] listTemp = CardCombination.GetCombinationCoChua(myPack, racMin);
if (listTemp != null)
{
listCC.AddRange(listTemp);
}
}
foreach (CardCombination cc in listCC)
{
if (cc.CompareTo(buoc.Cards) > 0)
{
cards = cc;
break;
}
}
}
return cards;
}
Expand Down
2 changes: 1 addition & 1 deletion vcards/ShareLibrary/GameLogicalObj/BuocDi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public CardCombination Cards
get { return cards; }
set { cards = value; }
}
LoaiBuocDi loaiBuocDi = LoaiBuocDi.BinhThuong;
LoaiBuocDi loaiBuocDi = LoaiBuocDi.BinhThuong; // cac thong tin tren la cua buoc truoc, thong tin nay la cua buoc hien tai
public LoaiBuocDi LoaiBuocDi
{
get { return loaiBuocDi; }
Expand Down
164 changes: 142 additions & 22 deletions vcards/ShareLibrary/GameLogicalObj/CardCombination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public static CardCombination CreateCombination(params CardLogical[] cards)
public static CardCombination[] GetCombinationCoChua(PackLogical pack, CardCombination cards)
{
//if nay co the bo???
if (!pack.IsHave(cards))
{
return null;
}
//if (!pack.IsHave(cards))
//{
// return null;
//}
PackLogical packNew = new PackLogical(pack);
List<CardCombination> listKQ = new List<CardCombination>();
listKQ.Add(cards);
Expand All @@ -84,7 +84,11 @@ public static CardCombination[] GetCombinationCoChua(PackLogical pack, CardCombi
if (card.CompareRank(cards[0])==0)
{
CardCombination temp = CardCombinationDoi.Create(card, cards[0]);
if (temp != null) listKQ.AddRange(GetCombinationCoChua(packNew, temp));
if (temp != null)
{
CardCombination[] list = GetCombinationCoChua(packNew, temp);
if (list!=null && list.Count()>0) listKQ.AddRange(list);
}
}
}
//doi thanh sanh
Expand All @@ -97,7 +101,11 @@ public static CardCombination[] GetCombinationCoChua(PackLogical pack, CardCombi
if (card2.Rank == cards[0].Rank + 2)
{
CardCombination temp = CardCombinationSanh.Create(cards[0], card1, card2);
if (temp != null) listKQ.AddRange(GetCombinationCoChua(packNew, temp));
if (temp != null)
{
CardCombination[] list = GetCombinationCoChua(packNew, temp);
if (list != null && list.Count() > 0) listKQ.AddRange(list);
}
}
}
}
Expand All @@ -106,44 +114,156 @@ public static CardCombination[] GetCombinationCoChua(PackLogical pack, CardCombi
}
else if (cards.GetType() == typeof(CardCombinationDoi))
{
//co the mo rong thanh tu quy, doi thong
CardLogical card1 = null;
CardLogical card2 = null;
//co the mo rong thanh sam co, tu quy, doi thong

//thu mo thanh sam co
foreach (CardLogical card in packNew.ListCards)
{
if (card.Rank == cards[0].Rank)
{
if (card1==null)
List<CardLogical> t = new List<CardLogical>();
t.AddRange(cards.ToArray());
t.Add(card);
CardCombination temp = CardCombinationSamCo.Create(t.ToArray());
if (temp != null)
{
card1 = card;
}
else
{
card2 = card;
CardCombination[] list = GetCombinationCoChua(packNew, temp);
if (list != null && list.Count() > 0) listKQ.AddRange(list);
}
}
}
if (card1!=null && card2!=null) //co them mot doi nua

//thu mo thanh tu quy
// khong mo rong doi thanh tu quy se bi trung khi mo rong sam co thanh tu quy
//foreach (CardLogical card1 in packNew.ListCards)
//{
// if (card1.Rank == cards[0].Rank)
// {
// foreach (CardLogical card2 in packNew.ListCards)
// {
// if (card2!=card1 && card2.Rank == cards[0].Rank)
// {
// List<CardLogical> t = new List<CardLogical>();
// t.AddRange(cards.ToArray());
// t.Add(card1);
// t.Add(card2);
// CardCombination temp = CardCombinationTuQuy.Create(t.ToArray());
// if (temp != null)
// {
// CardCombination[] list = GetCombinationCoChua(packNew, temp);
// if (list!=null && list.Count()>0) listKQ.AddRange(list);
// }
// }
// }
// }
//}

//thu mo thanh doi thong
foreach (CardLogical card1 in packNew.ListCards)
{
List<CardLogical> t = new List<CardLogical>();
t.AddRange(cards.ToArray());
t.Add(card1);
t.Add(card2);
CardCombination temp = CardCombinationTuQuy.Create(t.ToArray());
if (temp != null) listKQ.AddRange(GetCombinationCoChua(packNew, temp));
if (card1.Rank == cards[0].Rank+1)
{
foreach (CardLogical card2 in packNew.ListCards)
{
if (card2 != card1 && card2.Rank == cards[0].Rank+1)
{
foreach (CardLogical card3 in packNew.ListCards)
{
if (card3.Rank == cards[0].Rank+2)
{
foreach (CardLogical card4 in packNew.ListCards)
{
if (card3 != card4 && card4.Rank == cards[0].Rank+2)
{
List<CardLogical> t = new List<CardLogical>();
t.AddRange(cards.ToArray());
t.Add(card1);
t.Add(card2);
t.Add(card3);
t.Add(card4);
CardCombination temp = CardCombinationDoiThong.Create(t.ToArray());
if (temp != null)
{
CardCombination[] list = GetCombinationCoChua(packNew, temp);
if (list != null && list.Count() > 0) listKQ.AddRange(list);
}
}
}
}
}
}
}
}
}
}
else if (cards.GetType() == typeof(CardCombinationDoiThong))
{
//neu 3 doi thong thi thanh 4 doi, 4 thanh 5 doi
foreach (CardLogical card1 in packNew.ListCards)
{
if (card1.Rank == cards[0].Rank+1)
{
foreach (CardLogical card2 in packNew.ListCards)
{
if (card2 != card1 && card2.Rank == cards[0].Rank+1)
{
List<CardLogical> t = new List<CardLogical>();
t.AddRange(cards.ToArray());
t.Add(card1);
t.Add(card2);
CardCombination temp = CardCombinationDoiThong.Create(t.ToArray());
if (temp != null)
{
CardCombination[] list = GetCombinationCoChua(packNew, temp);
if (list != null && list.Count() > 0) listKQ.AddRange(list);
}
}
}
}
}
}
else if (cards.GetType() == typeof(CardCombinationSamCo))
{
//mo rong thanh tu quy
foreach (CardLogical card in packNew.ListCards)
{
if (card.Rank == cards[cards.CardsCount - 1].Rank)
{
List<CardLogical> t = new List<CardLogical>();
t.AddRange(cards.ToArray());
t.Add(card);
CardCombination temp = CardCombinationTuQuy.Create(t.ToArray());
if (temp != null)
{
CardCombination[] list = GetCombinationCoChua(packNew, temp);
if (list != null && list.Count() > 0) listKQ.AddRange(list);
}
break;
}
}
}
else if (cards.GetType() == typeof(CardCombinationSanh))
{
//them mot la
foreach (CardLogical card in packNew.ListCards)
{
if (card.Rank == cards[cards.CardsCount - 1].Rank+1)
{
List<CardLogical> t = new List<CardLogical>();
t.AddRange(cards.ToArray());
t.Add(card);
CardCombination temp = CardCombinationSanh.Create(t.ToArray());
if (temp != null)
{
CardCombination[] list = GetCombinationCoChua(packNew, temp);
if (list != null && list.Count() > 0) listKQ.AddRange(list);
}
}
}
}
else if (cards.GetType() == typeof(CardCombinationTuQuy))
{
//ko mo rong dc
}
return listKQ.ToArray();
}
Expand Down
4 changes: 4 additions & 0 deletions vcards/ShareLibrary/GameLogicalObj/CardCombinationSamCo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public static CardCombinationSamCo Create(params CardLogical[] cards)
}
public override int CompareTo(CardCombination cards)
{
if (this.GetType() != cards.GetType())
{
return 0;
}
return listCards[listCards.Count - 1].CompareValue(((CardCombinationSamCo)cards).listCards[listCards.Count - 1]);
}

Expand Down
4 changes: 4 additions & 0 deletions vcards/ShareLibrary/GameLogicalObj/CardCombinationSanh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public static CardCombinationSanh Create(params CardLogical[] cards)
}
public override int CompareTo(CardCombination cards)
{
if (this.GetType() != cards.GetType())
{
return 0;
}
if (listCards.Count != ((CardCombinationSanh)cards).listCards.Count)
{
return 0;
Expand Down
4 changes: 4 additions & 0 deletions vcards/ShareLibrary/GameLogicalObj/CardCombinationTuQuy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public static CardCombinationTuQuy Create(params CardLogical[] cards)
}
public override int CompareTo(CardCombination cards)
{
if (this.GetType() != cards.GetType())
{
return 0;
}
return listCards[listCards.Count - 1].CompareValue(((CardCombinationTuQuy)cards).listCards[listCards.Count - 1]);
}

Expand Down
6 changes: 5 additions & 1 deletion vcards/vCards/Gaming/GameManagerServer/BanChoi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public bool OnPlayerSkip(int iIndex)
}

bDaYeuCauPlayerDi = false;
if (bBuocDiDauTien) bBuocDiDauTien = false;

return true;
}
Expand Down Expand Up @@ -199,8 +200,11 @@ private void YeuCauPlayerDi()
bClientDaDi = false;
bDaYeuCauPlayerDi = true;
TurnToOtherPlayer();
if (turnList.Count>0)
if (turnList.Count > 0)
{
turnList.GetLastBuocDi().LoaiBuocDi = LoaiBuocDi.BinhThuong;
player[turnQueye[0]].OnYeuCauClientDi(turnList.GetLastBuocDi());
}
else
{
BuocDi b = new BuocDi();
Expand Down

0 comments on commit 4818e99

Please sign in to comment.