public ColourEnum[] GetLinePieces(int x, int y, int direction) { ColourEnum[] line = new ColourEnum[9]; int index = 0; ColourEnum colour = ColourEnum.Empty; for (int i = -4; i <= 4; i++) { index = 4 + i; if (i == 0) { continue; } if (direction == 0) { if (x + i >= 0 && x + i < 15) // -向 { colour = Table[x + i, y].Colour; } else { colour = ColourEnum.Out; } } if (direction == 1) { if (y + i >= 0 && y + i < 15) // |向 { colour = Table[x, y + i].Colour; } else { colour = ColourEnum.Out; } } if (direction == 2) { if (x - i >= 0 && x - i < 15 && y + i >= 0 && y + i < 15) // /向 { colour = Table[x - i, y + i].Colour; } else { colour = ColourEnum.Out; } } if (direction == 3) { if (x + i >= 0 && x + i < 15 && y + i >= 0 && y + i < 15) // \向 { colour = Table[x + i, y + i].Colour; } else { colour = ColourEnum.Out; } } line[index] = colour; } return(line); }
/// <summary> /// Temp colour code. As stated above should be driven from service. /// </summary> /// <param name="backingStore">Value to update</param> /// <param name="value">The new value</param> /// <param name="colour">Which colour is this</param> private void ToggleColour(ref bool backingStore, bool value, ColourEnum colour) { // Update the property on this VM SetProperty(ref backingStore, value); // Copy the existing colours to a new object so we can force an update (and trigger the binding to update) var colours = new ObservableRangeCollection <Colour>(); colours.AddRange(this.Person.Colours); // Also ensure the colours in the person's colour collection is correct if (value) { // The colour must be present if (!colours.Where(c => c.Id == (int)colour).Any()) { colours.Add(new Colour() { Id = (int)colour, Name = colour.ToString() }); } } else { // Make sure the colour is not there var existingColour = colours.FirstOrDefault(c => c.Id == (int)colour); if (existingColour != null) { colours.Remove(existingColour); } } // Update the colour collection and trigger the refresh this.Person.Colours = colours; }
public Cell(ColourEnum side1, ColourEnum side2, ColourEnum side3, ColourEnum side4) { _colours[0] = side1; // left _colours[1] = side2; // top _colours[2] = side3; // right _colours[3] = side4; // bottom }
public Piece(int x, int y, ColourEnum colour, int step = 0) { X = x; Y = y; Step = step; Colour = colour; //Title = $"X:{X} Y:{Y} Colour:{Colour.ToString()}"; }
private bool CheckIsWin(int x, int y) { //4个方向 for (int i = 0; i < 4; i++) { int count = 0; ColourEnum[] line = GetLinePieces(x, y, i); //落子点棋色 ColourEnum colour = Step % 2 == 1 ? ColourEnum.Black : ColourEnum.White; for (int j = 0; j < 9; j++) { //if (j == 4) continue; //不同色时计数清0 if (line[j] != colour) { count = 0; } else { count++; if (count == 5) { //白5连赢 if (colour == ColourEnum.White) { return(true); } //黑长连禁手 if (j + 1 >= 9 || line[j + 1] != colour) { return(true); } } } } } return(false); }
public Piece(int x, int y, ColourEnum colour) { X = x; Y = y; Colour = colour; }
public Piece() { X = 0; Y = 0; Colour = ColourEnum.Empty; }
public ColourBet(int player, int money, ColourEnum colour) : base(player, money) => BetCell = colour;
public Food(ColourEnum colour, double weight) { Colour = colour; Weight = weight; }
public Fish(ColourEnum c, double w, string type, bool scales) : base(c, w) { AnimalType = type; //Why ? WithScales = scales; }
private string GetName(ColourEnum[] line, ColourEnum colour, ColourEnum emp) { int Bs = 4, Bd = -1, Es = 4, Ed = 9, n = 1; string name = ""; //char[] line = str.ToCharArray();// 字符串拆成字符组 #region 遍历前后8点获得棋型信息 for (int i = 0; i <= 8; i++) { if (line[i] == emp || i == 4) { continue; // 如果空点或中点下一个 } if (line[i] != colour) // 为异色点时 { if (i < 4) // 中点之前 { Bd = i; // Bd为最后一个异色点坐标 if (Bs < i) // 如果之前有同色点 { Bs = 4; n = 1; }// 还原标志值 } else { Ed = i; break; } // 中点之后出现异色点跳出循环 } else // 为同色点时 { if (i < 4)// 中点之前 { if (Bs > i) { Bs = i;// Bs取第一个同色点坐标 } } else { Es = i; }// 中点之后取最后同色点坐标 n++;// n为同色计数器 } } #endregion #region 根据棋型信息返回名称 #region if (Es - Bs > 4) 如果是长连 if (Es - Bs > 4) // 长连 { int Scor = 0; // 分数标志 for (int i = Bs; i <= Es - 4; i++) // 长连中各个5个棋形组合 { int TempScor = 10; int bs = 0; int es = 0;// 临时分数、起始点、中止点 for (int j = 0; j <= 4; j++) { if (line[i + j] != emp) { TempScor = TempScor + 10; // 有一个点+10分 es = i + j; // 设中止点 if (bs == 0) { bs = i + j;// 设起始点 } if (bs - Bd == 1 || es + 1 == Ed) { TempScor = TempScor - 5;// 为“m”时-5分 } if (bs == 0 || es == 8) { TempScor = TempScor - 5; } } } if (TempScor > Scor) { Scor = TempScor;// 取最大的分值 } } if (Scor < 20) { return(""); } switch (Scor) { case 20: name = "h2"; break; case 25: name = "m3"; break; case 30: name = "h3"; break; case 35: name = "m4"; break; case 40: name = "h4"; break; case 45: name = "h5"; break; case 50: name = "h5"; break; default: break; } return(name); } #endregion if (Ed - Bd < 6) { return(name);// 异色起止点距离小于6时不成棋形返回“” } if (Ed - Bd == 6) { return("m" + n);// 异色起止点距离为6时“M” } if (Bs - Bd == 1 || Es + 1 == Ed) { return("m" + n); // 同色异色有相邻时“M” } if (Bs == 0 || Es == 8) // 同色在起点、中点或中点、止点时“M” { if (n == 2) { return(""); } return("m" + n); } if (n == 2) { if (Es - Bs >= n + 1) { return("t" + n); } return("h" + n); } if (Es - Bs >= n) { return("t" + n); } return("h" + n); #endregion }
public Apple(ColourEnum colour, double weight, string type) : base(colour, weight) { AnimalType = type; }
public ColouredDocument(ColourEnum colourEnum) { this.colour = colourEnum; }
public SetColourCommand(ColourEnum colour) { _colour = colour; }
private void BasicAnalyze() { //foreach (var relatedPiece in CurrentBoard.RelatedPieces) Parallel.ForEach(CurrentBoard.RelatedPieces, relatedPiece => { if (relatedPiece.Colour != ColourEnum.Empty) { return; //非空点跳过 } var info = GetPieceInfo(relatedPiece.X, relatedPiece.Y); relatedPieceInfos.Add(info); #region highLtB、highLevB if (info.Levels[ColourEnum.Black] == highLevB) { highLtB.Add(info); } else if ((int)info.Levels[ColourEnum.Black] < (int)highLevB) { highLevB = info.Levels[ColourEnum.Black]; highLtB.Clear(); highLtB.Add(info); } #endregion #region highLtW、highLevW if (info.Levels[ColourEnum.White] == highLevW) { highLtW.Add(info); } else if ((int)info.Levels[ColourEnum.White] < (int)highLevW) { highLevW = info.Levels[ColourEnum.White]; highLtW.Clear(); highLtW.Add(info); } #endregion #region m4LtB、m4LtW、forbiddenLt if (info.Names[ColourEnum.Black].Contains("m4")) { m4LtB.Add(info); } if (info.Names[ColourEnum.White].Contains("m4")) { m4LtW.Add(info); } if ((int)info.Levels[ColourEnum.Black] >= 9990) { forbiddenLt.Add(info); } #endregion }); int nextStep = CurrentBoard.Step + 1; ColourEnum nextColour = nextStep % 2 == 0 ? ColourEnum.White : ColourEnum.Black; #region 转换成攻防信息 if (nextColour == ColourEnum.Black) { highLevS = highLevB; highLtS = highLtB; m4LtS = m4LtB; highLevD = highLevW; highLtD = highLtW; m4LtD = m4LtW; } else { highLevS = highLevW; highLtS = highLtW; m4LtS = m4LtW; highLevD = highLevB; highLtD = highLtB; m4LtD = m4LtB; } #endregion Result = Analyze(highLevS, highLevD, highLtS, highLtD, m4LtS.Count, m4LtD.Count); }