public AiTest() { BrandPlayer[] player = new BrandPlayer[4]; BrandPlayer table = new BrandPlayer(); BrandFactory x = new BrandFactory(); x.createBrands(); x.randomBrands(); table = x.getBrands(); Deal deal = new Deal(16, table); deal.DealBrands(); player = deal.Player; printplayer(player); //SimpleAI sa = new SimpleAI(); //sa.setPlayer(player[0]); //PlayerSort bs = new PlayerSort(player[0]); //player[0] = bs.getPlayer(); //PlayerSort bs = new PlayerSort(player[0]); PlayerSort bs = new PlayerSort(player[0], new FlowerBrand(0), new TenThousandBrand(0), new RopeBrand(0), new TubeBrand(0), new WordBrand(0)); player[0] = bs.getPlayer; Level_1 l = new Level_1(); l.setPlayer(player[0]); l.getReadyBrand(); //printplayer(player); //Level_1 l = new Level_1(); //BrandPlayer test = new BrandPlayer(); //test.add(new WordBrand(1)); //test.add(new WordBrand(1)); //test.add(new WordBrand(1)); //test.add(new WordBrand(2)); //test.add(new WordBrand(3)); //test.add(new WordBrand(3)); //test.add(new WordBrand(3)); //test.add(new WordBrand(5)); //l.setPlayer(test); l.setPlayer(player[0]); Brand t = l.getReadyBrand(); Console.WriteLine("==>{0}{1}", t.getNumber(), t.getClass()); //printplayer(player); //sa.getReadyBrand(); //Console.WriteLine(); //Console.WriteLine("Ready Brand is {0},{1}", l.getReadyBrand().getClass(), l.getReadyBrand().getNumber()); }
private void add_to_player_iterator(Iterator iterator, BrandPlayer player) { while (iterator.hasNext()) { Brand brand = (Brand)iterator.next(); player.add(brand); } }
public byte[] getByteArrayWithObject(BrandPlayer players) { MemoryStream ms = new MemoryStream(); BinaryFormatter bf1 = new BinaryFormatter(); bf1.Serialize(ms, players); return(ms.ToArray()); }
BrandPlayer removefromplayer(Iterator iterator, BrandPlayer re) { while (iterator.hasNext()) { Brand brand = (Brand)iterator.next(); //re.remove(brand); Console.WriteLine(">>{0}", re.remove(brand)); } return(re); }
/// <summary> /// 建構基本玩家數量和分配數 /// </summary> /// <param name="countbrands">每一個玩家分配數</param> /// <param name="table">桌面玩家</param> public Deal(int countbrands, BrandPlayer table) { this.countbrands = countbrands; this.countplayer = 4; this.player = new BrandPlayer[countplayer]; this.table = table; for (int i = 0; i < countplayer; i++) { this.player[i] = new BrandPlayer(); } }
/// <summary> /// ノ睹计р礟ゴ睹 /// </summary> public void randomBrands() { creatRandomTable(); BrandPlayer tempplayer = new BrandPlayer(); //ㄌ酚睹计硋р礟產い for (int i = 0; i < this.player.getCount(); i++) { tempplayer.add(this.player.getBrand((int)randomTable[i])); } this.player = tempplayer; }
private void addimage_player(BrandPlayer player, location state, RotateFlipType rotate) { Iterator temp = player.creatIterator(); addimage_iterator(temp, state, rotate); if (InvokeRequired) { Invoke(new Update_delegate(Update)); } else { Update(); } }
/// <summary> /// 牌的狀態檢查 暗槓 /// </summary> /// <param name="player">牌玩家</param> public CheckBrands(BrandPlayer player) { for (int i = 0; i < player.getCount(); i++) { if (player.getBrand(i).getClass() != Mahjong.Properties.Settings.Default.Flower) { x.add(player.getBrand(i)); } } for (int i = 0; i < chow_player.Length; i++) { chow_player[i] = new BrandPlayer(); } }
public DealTest() { BrandPlayer[] player = new BrandPlayer[4]; BrandPlayer table = new BrandPlayer(); BrandFactory x = new BrandFactory(); x.createBrands(); x.randomBrands(); table = x.getBrands(); Console.WriteLine("共有: {0}", table.getCount()); // 印出洗好的牌 printplayer(table, "亂數牌"); PlayerSort bbs = new PlayerSort(table); BrandPlayer sort_table = bbs.getPlayer; printplayer(sort_table, "亂數排序回去"); // 分配牌 Deal deal = new Deal(16, table); deal.DealBrands(); player = deal.Player; // 印出全部的玩家 printplayer(player); BrandPlayer check = new BrandPlayer(); foreach (BrandPlayer b in player) { for (int i = 0; i < b.getCount(); i++) { check.add(b.getBrand(i)); } } for (int i = 0; i < table.getCount(); i++) { check.add(table.getBrand(i)); } PlayerSort bs = new PlayerSort(check); check = bs.getPlayer; Console.WriteLine("\n共有: {0}", check.getCount()); printplayer(check, "重新檢查"); }
/// <summary> /// 設定群組號碼 /// </summary> /// <param name="player">玩家</param> private void set_Team(BrandPlayer player, bool isCanSee) { teamCount[state]++; // 把牌從現在玩家手上移出 for (int i = 0; i < player.getCount(); i++) { NowPlayer.remove(player.getBrand(i)); } // 把牌設為可視並且加上組別號碼後加回現在玩家 for (int i = 0; i < player.getCount(); i++) { player.getBrand(i).IsCanSee = isCanSee; player.getBrand(i).Team = teamCount[state]; NowPlayer.add(player.getBrand(i)); } }
void addimage_to_FlowLayout(FlowLayoutPanel flow, BrandPlayer player, EventHandler ev) { for (int i = 0; i < player.getCount(); i++) { Bitmap bitmap = new Bitmap(ResourcesTool.getImage(player.getBrand(i))); BrandBox b = new BrandBox(player.getBrand(i)); b.SizeMode = PictureBoxSizeMode.AutoSize; bitmap = ResizeBitmap(bitmap, Mahjong.Properties.Settings.Default.ResizePercentage); b.Click += ev; b.Image = bitmap; flow.Controls.Add(b); } }
/// <summary> /// 分配牌 /// </summary> public void DealBrands() { BrandPlayer temp = new BrandPlayer(); // 讀出數量的牌,並移除 for (int i = 0; i < countplayer * countbrands; i++) { Brand brand = table.getBrand(i); temp.add(brand); table.remove(brand); } // 把牌加入玩家 for (int i = 0; i < temp.getCount(); i++) { player[i % countplayer].add(temp.getBrand(i)); } }
void addscore_順子(BrandPlayer brandclass, int score) { BrandPlayer[] temp = new BrandPlayer[9]; for (int j = 0; j < temp.Length; j++) { temp[j] = new BrandPlayer(); } //將brands陣列每個數的值,丟到use_Dots分類 for (int i = 0; i < brandclass.getCount(); i++) { for (int j = 1; j <= temp.Length; j++) { if (brandclass.getBrand(i).getNumber() == j) { temp[j - 1].add(brandclass.getBrand(i)); } } } for (int i = 0; i < temp.Length - 2; i++) { if (temp[i].getCount() >= 1) { if (temp[i + 1].getCount() >= 1) { if (temp[i + 2].getCount() >= 1) { for (int j = 0; j < temp[i].getCount(); j++) { temp[i].getBrand(j).Source += score; } for (int j = 0; j < temp[i + 1].getCount(); j++) { temp[i + 1].getBrand(j).Source += score; } for (int j = 0; j < temp[i + 2].getCount(); j++) { temp[i + 2].getBrand(j).Source += score; } } } } } }
public BrandFactory() { this.player = new BrandPlayer(); countFlowerBrand = 8; pieceFlowerBrand = 1; countRopeBrand = 9; pieceRopeBrand = 4; countTubeBrand = 9; pieceTubeBrand = 4; countTenThousandBrand = 9; pieceTenThousandBrand = 4; countWordBrand = 7; pieceWordBrand = 4; creatImageArray(); sumBrands = countFlowerBrand * pieceFlowerBrand + countRopeBrand * pieceRopeBrand + countTenThousandBrand * pieceTenThousandBrand + countTubeBrand * pieceTubeBrand + countWordBrand * pieceWordBrand; }
void addscore_for_step7(BrandPlayer b) { BrandPlayer[] temp = new BrandPlayer[9]; for (int j = 0; j < temp.Length; j++) { temp[j] = new BrandPlayer(); } //將brands陣列每個數的值,丟到step7_characters分類 for (int i = 0; i < b.getCount(); i++) { for (int j = 1; j <= temp.Length; j++) { if (b.getBrand(i).getNumber() == j) { temp[j - 1].add(b.getBrand(i)); } } } //聽二張為順牌+40,並減掉二張牌差異數(*5) for (int i = 1; i < temp.Length - 2; i++) { if (temp[i - 1].getCount() == 0) { if (temp[i].getCount() >= 1) { if (temp[i + 1].getCount() >= 1) { if (temp[i + 2].getCount() == 0) { for (int j = 0; j < temp[i].getCount(); j++) { temp[i].getBrand(j).Source += 40; temp[i].getBrand(j).Source -= 5; } for (int j = 0; j < temp[i + 1].getCount(); j++) { temp[i + 1].getBrand(j).Source += 40; temp[i + 1].getBrand(j).Source -= 5; } } } } } } //聽一張為順牌+20,並減掉二張牌差異數(*5) for (int i = 0; i < temp.Length - 2; i++) { if (temp[i].getCount() >= 1) { if (temp[i + 1].getCount() == 0) { if (temp[i + 2].getCount() == 1) { for (int j = 0; j < temp[i].getCount(); j++) { temp[i].getBrand(j).Source += 20; temp[i].getBrand(j).Source -= 10; } for (int j = 0; j < temp[i + 2].getCount(); j++) { temp[i + 2].getBrand(j).Source += 20; temp[i + 2].getBrand(j).Source -= 10; } } } } } //聽一張為順牌的例外情況:(1、2)和(8、9) for (int i = 0; i < temp.Length - 1; i = i + 7) { if (i <= 1) { if (temp[i].getCount() >= 1) { if (temp[i + 1].getCount() >= 1) { if (temp[i + 2].getCount() == 0) { for (int j = 0; j < temp[i].getCount(); j++) { temp[i].getBrand(j).Source += 20; temp[i].getBrand(j).Source -= 5; } for (int j = 0; j < temp[i + 1].getCount(); j++) { temp[i + 1].getBrand(j).Source += 20; temp[i + 1].getBrand(j).Source -= 5; } } } } } if (i >= 1) { if (temp[i - 1].getCount() == 0) { if (temp[i].getCount() >= 1) { if (temp[i + 1].getCount() >= 1) { for (int j = 0; j < temp[i].getCount(); j++) { temp[i].getBrand(j).Source += 20; temp[i].getBrand(j).Source -= 5; } for (int j = 0; j < temp[i + 1].getCount(); j++) { temp[i + 1].getBrand(j).Source += 20; temp[i + 1].getBrand(j).Source -= 5; } } } } } } }
void add_to_player(BrandPlayer player, BrandPlayer add) { Iterator temp = player.creatIterator(); add_to_player_iterator(temp, add); }
/// <summary> /// 暗槓 /// </summary> /// <param name="brand">要槓的牌</param> /// <param name="player">可以槓的牌組</param> public void DarkKong(Brand brand, BrandPlayer player) { set_Team(player, false); }
/// <summary> /// 槓 /// </summary> /// <param name="brand">要槓的牌</param> /// <param name="player">可以槓的牌組</param> public void kong(Brand brand, BrandPlayer player) { Show_Table.remove(brand); set_Team(player, true); }
/// <summary> /// 胡牌 成立 /// </summary> /// <returns>是/否</returns> public bool Win() { if (brand != null) { x.add(brand); PlayerSort d = new PlayerSort(x); x = d.getPlayer; } brand_2(); bradn_4(); bradn_3(); // 組合測試 // a 三支 // b 兩隻 // c 組合 int count = 0; for (int i = 0; i < a.getCount(); i += 3) { for (int j = i + 3; j < a.getCount(); j += 3) { for (int k = j + 3; k < a.getCount(); k += 3) { for (int l = k + 3; l < a.getCount(); l += 3) { for (int m = l + 3; m < a.getCount(); m += 3) { for (int n = 0; n < b.getCount(); n += 2) { c.clear(); c.add(a.getBrand(i)); c.add(a.getBrand(i + 1)); c.add(a.getBrand(i + 2)); c.add(a.getBrand(j)); c.add(a.getBrand(j + 1)); c.add(a.getBrand(j + 2)); c.add(a.getBrand(k)); c.add(a.getBrand(k + 1)); c.add(a.getBrand(k + 2)); c.add(a.getBrand(l)); c.add(a.getBrand(l + 1)); c.add(a.getBrand(l + 2)); c.add(a.getBrand(m)); c.add(a.getBrand(m + 1)); c.add(a.getBrand(m + 2)); c.add(b.getBrand(n)); c.add(b.getBrand(n + 1)); PlayerSort d = new PlayerSort(c); c = d.getPlayer; //牌的比對 //完全成立代表胡牌 for (int o = 0; o < x.getCount(); o++) { if (c.getBrand(o).getClass() == x.getBrand(o).getClass() && c.getBrand(o).getNumber() == x.getBrand(o).getNumber()) { count = o; continue; } else { break; } } if (count == x.getCount() - 1) { if (brand != null) { x.remove(brand); } return(true); // 成立 } } } } } } } if (brand != null) { x.remove(brand); } return(false); }
public void setPlayer(BrandPlayer player) { x = player; }
public void setPlayer(Brand brand, BrandPlayer player) { this.brandplayer = player; }
public SimpleAI(BrandPlayer player) { this.brandplayer = player; }
public TallyTest() { BrandPlayer a = new BrandPlayer(); a.add(new TubeBrand(1)); a.add(new TubeBrand(1)); a.add(new TubeBrand(1)); a.add(new TubeBrand(1)); a.add(new RopeBrand(1)); a.add(new RopeBrand(1)); a.add(new RopeBrand(1)); a.add(new RopeBrand(1)); a.add(new TenThousandBrand(1)); a.add(new TenThousandBrand(1)); a.add(new TenThousandBrand(1)); a.add(new TenThousandBrand(1)); a.add(new TubeBrand(9)); a.add(new TubeBrand(9)); a.add(new TubeBrand(9)); a.add(new TubeBrand(9)); a.add(new RopeBrand(9)); a.add(new RopeBrand(9)); a.add(new RopeBrand(9)); a.add(new RopeBrand(9)); //a.add(new WordBrand(4)); a.add(new WordBrand(4)); a.add(new WordBrand(4)); ////a.add(new WordBrand(1)); //a.add(new WordBrand(1)); //a.add(new WordBrand(1)); //a.add(new WordBrand(1)); ////a.add(new WordBrand(2)); //a.add(new WordBrand(2)); //a.add(new WordBrand(2)); //a.add(new WordBrand(2)); ////a.add(new WordBrand(3)); //a.add(new WordBrand(3)); //a.add(new WordBrand(3)); //a.add(new WordBrand(3)); f = new Tally(); Location l = new Location(); AllPlayers all = new AllPlayers(4, 16); WordBrand w = new WordBrand(9); WordBrand v = new WordBrand(9); w.WhoPush = location.East; //v.WhoPush = location.Table; all.Show_Table.add(w); //all.NowPlayer.add(v); f.setPlayer(all); f.setPlayer(a); //l.next_Winer(); f.setLocation(l, 0); f.ShowDialog(); }
public CheckTest() { BrandPlayer a = new BrandPlayer(); //a.add(new TenThousandBrand(5)); //a.add(new TenThousandBrand(6)); //a.add(new TenThousandBrand(7)); //a.add(new TenThousandBrand(6)); //a.add(new TenThousandBrand(7)); //a.add(new TenThousandBrand(8)); //a.add(new RopeBrand(4)); //a.add(new RopeBrand(5)); //a.add(new RopeBrand(6)); a.add(new TubeBrand(2)); a.add(new TubeBrand(2)); a.add(new TubeBrand(2)); //a.add(new TubeBrand(2)); //a.add(new TubeBrand(5)); //a.add(new TubeBrand(8)); //a.add(new TubeBrand(8)); //FlowerBrand f = new FlowerBrand(1); //f.Team = 1; //a.add(f); //WordBrand r = new WordBrand(9); ////r.Team = 2; //a.add(r); //a.add(r); //a.add(r); ////a.add(r); //TubeBrand t = new TubeBrand(9); //t.Team = 3; //a.add(t); //a.add(t); //a.add(t); //a.add(new TubeBrand(2)); //a.add(new TubeBrand(2)); //a.add(new TubeBrand(3)); //a.add(new TubeBrand(3)); //a.add(new TubeBrand(3)); //a.add(new TubeBrand(3)); //a.add(new TubeBrand(9)); //a.add(new TubeBrand(9)); //WordBrand w = new WordBrand(6); //w.Team = 2; //a.add(w); //a.add(w); //a.add(w); //a.add(w); //Brand b = new TubeBrand(2); //CheckUser c = new Check(b,a); printplayer(a); CheckBrands c = new CheckBrands(new TubeBrand(2), a); a.add(new TubeBrand(2)); CheckBrands d = new CheckBrands(a); //if (c.Win()) //{ // Console.WriteLine("有胡!!"); // printplayer(c.SuccessPlayer); //} if (c.Chow()) { Console.WriteLine("==========="); Console.WriteLine("\n有吃"); Console.WriteLine(c.ChowLength); printplayer(c.SuccessPlayer); printplayer(c.ChowPlayer[0]); printplayer(c.ChowPlayer[1]); printplayer(c.ChowPlayer[2]); Console.WriteLine("==========="); } if (c.Pong()) { Console.WriteLine("\n有碰"); printplayer(c.SuccessPlayer); } if (c.Kong()) { Console.WriteLine("\n有槓"); printplayer(c.SuccessPlayer); } if (d.DarkKong()) { Console.WriteLine("\n有暗槓"); printplayer(c.SuccessPlayer); } if (//!c.Win() && !c.Chow() && !c.Pong() && !c.Kong() && !c.DarkKong()) { Console.WriteLine("\n都沒"); } printplayer(a); }
void step6() { //===== //Step6 以圖案為群組,一組花色有9張,各別加上0,5,10,15,20,15,10,5,0 //===== int[] const_value = new int[9]; const_value[0] = 0; const_value[1] = 5; const_value[2] = 10; const_value[3] = 15; const_value[4] = 20; const_value[5] = 15; const_value[6] = 10; const_value[7] = 5; const_value[8] = 0; // //萬 // BrandPlayer[] step6_characters = new BrandPlayer[9]; for (int j = 0; j < step6_characters.Length; j++) { step6_characters[j] = new BrandPlayer(); } //將brands陣列每個數的值,丟到use_characters分類 for (int i = 0; i < brands[1].getCount(); i++) { for (int j = 1; j <= step6_characters.Length; j++) { if (brands[1].getBrand(i).getNumber() == j) { step6_characters[j - 1].add(brands[1].getBrand(i)); } } } for (int i = 0; i < step6_characters.Length; i++) { if (step6_characters[i].getCount() >= 1) { for (int j = 0; j < step6_characters[i].getCount(); j++) { step6_characters[i].getBrand(j).Source += const_value[i]; } } } // //筒 // BrandPlayer[] step6_Dots = new BrandPlayer[9]; for (int j = 0; j < step6_Dots.Length; j++) { step6_Dots[j] = new BrandPlayer(); } //將brands陣列每個數的值,丟到use_characters分類 for (int i = 0; i < brands[2].getCount(); i++) { for (int j = 1; j <= step6_Dots.Length; j++) { if (brands[2].getBrand(i).getNumber() == j) { step6_Dots[j - 1].add(brands[2].getBrand(i)); } } } for (int i = 0; i < step6_Dots.Length; i++) { if (step6_Dots[i].getCount() >= 1) { for (int j = 0; j < step6_Dots[i].getCount(); j++) { step6_Dots[i].getBrand(j).Source += const_value[i]; } } } // //條 // BrandPlayer[] step6_Bamboos = new BrandPlayer[9]; for (int j = 0; j < step6_Bamboos.Length; j++) { step6_Bamboos[j] = new BrandPlayer(); } //將brands陣列每個數的值,丟到use_characters分類 for (int i = 0; i < brands[3].getCount(); i++) { for (int j = 1; j <= step6_Bamboos.Length; j++) { if (brands[3].getBrand(i).getNumber() == j) { step6_Bamboos[j - 1].add(brands[3].getBrand(i)); } } } for (int i = 0; i < step6_Bamboos.Length; i++) { if (step6_Bamboos[i].getCount() >= 1) { for (int j = 0; j < step6_Bamboos[i].getCount(); j++) { step6_Bamboos[i].getBrand(j).Source += const_value[i]; } } } }