public Tuple <int, int> getComputerMove() { Random rnd = new Random(); int row, column; do { row = rnd.Next(0, boardSize); column = rnd.Next(0, boardSize); } while (board[row, column] != Type.noValue); //return new Tuple<int, int>(row, column); boardForAI = new Type[boardSize, boardSize]; for (int i = 0; i < boardSize; i++) { for (int j = 0; j < boardSize; j++) { boardForAI[i, j] = board[i, j]; } } analyzeGomoku(Type.computer); var result = bestGomokuMove(true, depth); Console.WriteLine("best move: x = " + result.Item1 + " y = " + result.Item2); return(new Tuple <int, int>(result.Item1, result.Item2)); }
private void buttonLoad_Click(object sender, EventArgs e) { DialogResult dr = openFileDialog.ShowDialog(); string path = ""; if (dr == DialogResult.Cancel) { return; } if (dr == DialogResult.OK) { path = openFileDialog.FileName; } //ok we get the file... now try { FileStream inFileStream = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryFormatter deseralizer = new BinaryFormatter(); sandArray = (Type[, ])deseralizer.Deserialize(inFileStream); } catch (Exception ex) { MessageBox.Show("Cant load file... \n" + ex.Message); } }
public static Point MaxMin(ChessBoard chessBoard, Type type) { count = 0; cut = 0; int best = -Max; Type typeofman = type == Type.Black ? Type.White : Type.Black; Type[,] typeboard = ChessBoard_Trans_TypeBoard(chessBoard); Point[] nextposition = GeneraterNextPosition(typeboard, type); Stack <Point> bestposition = new Stack <Point>(225); for (int i = 0; i < nextposition.Length; i++) { count++;//----------------------------------- Point newpoint = nextposition[i]; typeboard[newpoint.X, newpoint.Y] = type; int value = Min_value(typeboard, typeofman, deepMax - 1, -Max, Max); if (value == best) { bestposition.Push(newpoint); } else if (value > best) { best = value; bestposition.Clear(); bestposition.Push(newpoint); } typeboard[newpoint.X, newpoint.Y] = Type.Empety; } Random random = new Random(); return((bestposition.ToArray())[random.Next(0, bestposition.ToArray().Length)]); }
MethodInfo[] GetSpecificParamMethods(Type[,] types, BindingFlags flags) { List <MethodInfo> verifiedMethods = new List <MethodInfo>(); MethodInfo[] methodsInfo = GetMethods(flags); foreach (MethodInfo methodInfo in methodsInfo) { bool flag = false; ParameterInfo[] parameters = methodInfo.GetParameters(); //Check if methode is of right signature for event manager for (int i = 0; i < types.Length; i++) { if (parameters.Length == types.GetUpperBound(0)) { for (int j = 0; j < parameters.Length; j++) { flag = false; if (parameters[j].ParameterType == types[i, j]) { flag = true; } } if (flag) { verifiedMethods.Add(methodInfo); break; } } } } return(verifiedMethods.ToArray()); }
public Board(Type[,] board) { numWhiteNormalPieces = 0; numBlackNormalPieces = 0; numBlackKingPieces = 0; numWhiteKingPieces = 0; this.board = board; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { Type piece = getPiece(i, j); if (piece == Type.BLACK) { numBlackNormalPieces++; } else if (piece == Type.BLACK_KING) { numBlackKingPieces++; } else if (piece == Type.WHITE) { numWhiteNormalPieces++; } else if (piece == Type.WHITE_KING) { numWhiteKingPieces++; } } } }
public NDArray(Type[,] nD) { if (nD == null) { throw new ArgumentException(); } int dim0 = nD.GetLength(0); int dim1 = nD.GetLength(1); int dim = dim0 * dim1; Shape = new int[] { dim0, dim1 }; tmpArr = new int[Shape.Length]; items = new Type[dim]; int a = 0; for (int i = 0; i < dim0; ++i) { for (int j = 0; j < dim1; ++j) { items[a++] = nD[i, j]; } } }
// Non-generic test public static void TestMono() { string[,] x = new string[1, 1]; Console.WriteLine(x.GetType()); Type[,] y = Inlinable(); Console.WriteLine(y.GetType()); }
// 得到有邻居的空白位置(已经按远近排序)目前只计算一步的。 public static Point[] GetChessArray_HasNeighbor(Type[,] typeboard) { List <Point> onestepneighbour = new List <Point>(120), twostepneighbour = new List <Point>(120); Point[] hasNeighbourArray; for (int i = 0; i < 15; i++) { for (int j = 0; j < 15; j++) { Point p = new Point(i, j); if (typeboard[i, j] == Type.Empety) { if (HasNstepNeighbor(typeboard, p, 1)) { onestepneighbour.Add(p); } /* if (HasNstepNeighbor(typeboard, p, 2)) * { * twostepneighbour.Add(p); * }*/ } } } hasNeighbourArray = onestepneighbour.Concat(twostepneighbour).ToArray(); return(hasNeighbourArray); }
private static void ArrayCasting() { // Create a 2-dim FileStream array FileStream[,] fs2dim = new FileStream[5, 10]; // Implicit cast to a 2-dim Object array Object[,] o2dim = fs2dim; // Can't cast from 2-dim array to 1-dim array // Compiler error CS0030: Cannot convert type 'object[*,*]' to 'System.IO.Stream[]' //Stream[] s1dim = (Stream[]) o2dim; // Explicit cast to 2-dim Stream array Stream[,] s2dim = (Stream[, ])o2dim; // Explicit cast to 2-dim Type array // Compiles but throws InvalidCastException at runtime try { Type[,] t2dim = (Type[, ])o2dim; } catch (InvalidCastException) { } // Create a 1-dim Int32 array (value types) Int32[] i1dim = new Int32[5]; // Can't cast from array of value types to anything else // Compiler error CS0030: Cannot convert type 'int[]' to 'object[]' // Object[] o1dim = (Object[]) i1dim; // However, Array.Copy knows how to coerce an array // of value types to an array of boxed references Object[] o1dim = new Object[i1dim.Length]; Array.Copy(i1dim, o1dim, 0); }
private void setUpBoard() { numWhiteNormalPieces = 12; numBlackNormalPieces = 12; numBlackKingPieces = 0; numWhiteKingPieces = 0; board = new Type[SIZE, SIZE]; // Borad.Length for (int i = 0; i < SIZE; i++) { int start = 0; if (i % 2 == 0) { start = 1; } Type pieceType = Type.EMPTY; if (i <= 2) { pieceType = Type.WHITE; } else if (i >= 5) { pieceType = Type.BLACK; } // Borad.Length for (int j = start; j < SIZE; j += 2) { board[i, j] = pieceType; } } populateEmptyOnBoard(); }
bool checkForwardCircuits(NodePosition sourcePosition, ref Type[,] connections, Direction initialDirection, ref HashSet <NodePosition> discovered) { shortCircuit = false; bool finished = false; validPath = new Stack <NodePosition>(); //checks if children made a correct connection to goal or not bool notConnected = false; //begin initializing Stack search case with first source node List <NodePosition> adjacentConnectors = CircuitComponent.adjMatrix(sourcePosition, initialDirection); switch (initialDirection) { case Direction.Left: break; case Direction.Up: break; case Direction.Right: break; case Direction.Down: break; } return(false); }
/***returns protocol for type of connections found * Even = good connections * Odd = no connection or error * -1 = short circuit * 0 = connected to lightbulb * */ int validateConnections(NodePosition sourcePosition, ref Type[,] connections, Direction direction, ref HashSet <NodePosition> discovered) { if (discovered.Contains(sourcePosition)) { return(1); } //checks if position in bounds of the circuitBoard if ((sourcePosition.x < connections.GetLength(0) && sourcePosition.x >= 0) && (sourcePosition.y < connections.GetLength(1) && sourcePosition.y >= 0)) { if (connections[sourcePosition.x, sourcePosition.y] == Type.Goal) { return(0); } else if (connections[sourcePosition.x, sourcePosition.y] == Type.Wires) { return(2); } else if (connections[sourcePosition.x, sourcePosition.y] == Type.Battery) { return(-1); } else { discovered.Add(sourcePosition); return(1); } } return(1); }
/// <summary> /// Escribe en la consola el contenido de un vector bi-dimencional, agregando un encabezado para cada columna. /// <returns></returns> public static bool EscribirMatriz <Type>(string[] prmVectorEncabezados, Type[,] prmMatriz, bool prmAlinearDerecha) { try { if (prmAlinearDerecha) { for (int varIteradorColumna = 0; varIteradorColumna < prmMatriz.GetLength(1); varIteradorColumna++) { Console.WriteLine(prmVectorEncabezados[varIteradorColumna]); for (int varIteradorFila = 0; varIteradorFila < prmMatriz.GetLength(0); varIteradorFila++) { Console.WriteLine("\t" + prmMatriz[varIteradorFila, varIteradorColumna]); } } } else { for (int varIteradorColumna = 0; varIteradorColumna < prmMatriz.GetLength(1); varIteradorColumna++) { for (int varIteradorFila = 0; varIteradorFila < prmMatriz.GetLength(0); varIteradorFila++) { Console.WriteLine(prmMatriz[varIteradorFila, varIteradorColumna]); } } } return(true); } catch (Exception) { Console.WriteLine("Hubo un error inesperado. "); return(false); }; }
public void startGame() { foreach (Transform child in transform) { Destroy(child.gameObject); } n = int.Parse(col.text); m = int.Parse(row.text); AI_difficult = int.Parse(dif.text); boardItem = new GameObject[m, n]; InitWith(n, m); GridLayoutGroup grid = transform.GetComponent <GridLayoutGroup>(); grid.cellSize = new Vector2(width / n, height / m); board = new Type[m, n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { board[i, j] = Type.None; } } //BOT here minimaxBOT = new TicTacToe_Minimax_AI.TicTacToeGame(m, n); ///////////////////////////////////////////////////////// whoseTurn = Type.Player; stateMessage.text = "It's your turn!"; }
private static void FillIdentities(Type[] typeList, Type[,] table) { for (int i = 0; i <= typeList.Length - 1; i++) { Type t = typeList[i]; table[i, i] = t; } }
void checkCircuit(NodePosition sourcePosition, ref Type[,] connections, Direction direction, int goalCount) { discovered = new HashSet <NodePosition>(); discovered.Add(sourcePosition); path = new Stack <NodePosition>(); numGoals = goalCount; checkForwardCircuits(sourcePosition, ref connections, direction, ref discovered); }
private static void FillIdentities(Type[] typeArray, Type[,] table) { for (var i = 0; i <= typeArray.Length - 1; i++) { var type = typeArray[i]; table[i, i] = type; } }
// Use this for initialization void Start() { controller = new CircuitController(); bulbFirst = new NodePosition[2] { new NodePosition(3, 1), new NodePosition(7, 2) }; // Input ourselve bulbSecond = new NodePosition[2] { new NodePosition(4, 1), new NodePosition(7, 3) }; // Input ourselve resistorFirst = new NodePosition[4] { new NodePosition(2, 0), new NodePosition(2, 1), new NodePosition(2, 2), new NodePosition(3, 2) }; // Input ourselve resistorSecond = new NodePosition[4] { new NodePosition(2, 1), new NodePosition(2, 2), new NodePosition(3, 2), new NodePosition(4, 2) }; // Input ourselve BatteryFirst = new NodePosition(0, 1); BatterySecond = new NodePosition(0, 2); saveConnection = new GameObject[xSize * 2 + 1, ySize + 1]; dragging = false; node = new GameObject[xSize, ySize]; for (int j = 0; j < ySize; j++) { for (int i = 0; i < xSize; i++) { node [i, j] = GameObject.Find("Node(" + i + "," + j + ")"); } } connections = new Type [xSize * 2 + 1, ySize + 1]; for (int i = 0; i <= xSize * 2; i += 2) { for (int j = 0; j <= ySize - 1; j++) { saveConnection [i, j] = null; connections [i, j] = Type.None; } } for (int i = 1; i <= xSize * 2; i += 2) { for (int j = 0; j <= ySize; j++) { saveConnection [i, j] = null; connections [i, j] = Type.None; } } for (int i = 0; i < 2; i++) { InstanceBulb(bulbFirst [i], bulbSecond [i]); } for (int i = 0; i < 4; i++) { InstanceResistor(resistorFirst [i], resistorSecond [i]); } InstanceBattery(BatteryFirst, BatterySecond); button.onClick.AddListener(runAlgorithm); }
private void setUpTestBoard() { numBlackKingPieces = 1; numWhiteKingPieces = 1; board = new Type[SIZE, SIZE]; board[6, 1] = Type.WHITE_KING; board[4, 3] = Type.BLACK_KING; populateEmptyOnBoard(); }
public void PreareMap() { // Map情報を初期化 // 画面サイズは320x320ピクセル、1マスあたり4ピクセルとして扱う // 1マス毎にMap情報を格納する // 格納する情報は320/4の80x80の二次元配列となる if (m_Prefab == null) { m_Prefab = new GameObject[w / m_GridSize, h / m_GridSize]; } m_Type = new Type[w / m_GridSize, h / m_GridSize]; GameObject prefab = null; Type type = Type.FIELD; m_InitialFieldValue = 0; for (int x = 0; x < w / m_GridSize; x++) { for (int y = 0; y < h / m_GridSize; y++) { // Mapの初期状態の画像を読み込み、色情報からGameObjectを生成する Color color = m_Texture.GetPixel(x * m_GridSize, y * m_GridSize); if (color.Equals(new Color(15.0f / 255.0f, 56.0f / 255.0f, 15.0f / 255.0f))) { type = Type.BORDER_LINE; prefab = m_BorderlinePrefab; } if (color.Equals(new Color(155.0f / 255.0f, 188.0f / 255.0f, 15.0f / 255.0f))) { type = Type.FIELD; prefab = m_FieldPrefab; m_InitialFieldValue++; } if (color.Equals(new Color(139.0f / 255.0f, 172.0f / 255.0f, 15.0f / 255.0f))) { type = Type.OUTSIDE; prefab = m_OutsidePrefab; } //Debug.Log("(" + x*4 + "," + y*4 + ") " + state +"|"+color); Vector2 position = new Vector2((float)x * m_GridSize, (float)y * m_GridSize); position = Camera.main.ScreenToWorldPoint(position); // 2週目以降に前回プレイ時のMapを破棄する Destroy(m_Prefab[x, y]); m_Prefab[x, y] = Instantiate(prefab, position, Quaternion.identity); m_Prefab[x, y].transform.parent = transform; m_Type[x, y] = type; } } }
private static void FillIdentities(Type[] typeList, Type[,] table) { var num = typeList.Length - 1; for (var i = 0; i <= num; i++) { var t = typeList[i]; table[i, i] = t; } }
internal void Fill <Type>(ref Type[,] x, Type a)//配列の定数敷き詰め { for (int i0 = 0; i0 < x.GetLength(0); i0++) { for (int i1 = 0; i1 < x.GetLength(1); i1++) { x[i0, i1] = a; } } }
public static void Loop <Type>(this Type[,] array, Action <Type> DoThing) { for (int k = 0; k < array.GetLength(0); k++) { for (int l = 0; l < array.GetLength(1); l++) { DoThing(array[k, l]); } } }
//对空白打分--------------------------------------------------------------------------------------------- public static int[,] GetScoreTable(Type[,] typeboard, Type type) //得出当前棋局适当空位分数(模拟下棋) { int[,] scoretable = new int[15, 15]; Point[] pointarray = GetChessArray_HasNeighbor(typeboard); for (int i = 0; i < pointarray.Length; i++) { scoretable[pointarray[i].X, pointarray[i].Y] = GetScore_emptyPoint(typeboard, type, pointarray[i]); //对当前棋局对该空位模拟下某色棋子后形成的局面得分 } return(scoretable); }
public static int GetScore_emptyPoint(Type[,] typeboard, Type type, Point point)//对一个位置下某色棋子时进行打分 { Score[] scores = JudgeType_emptyPoint(typeboard, type, point); int score = 0; for (int i = 0; i <= 3; i++) { score += (int)scores[i]; } return(score); }
private static int FindElevator(Type[,] area, int floor) { for (var i = 0; i < area.GetLength(0); i++) { if (area[i, floor] == Type.Elevator) { return(i); } } return(-1); }
/// <summary> /// コンストラクタ /// </summary> /// <param name="initValue">ボードの初期値</param> /// <param name="boardSize">ボードの大きさ</param> public Board(Type initValue, int boardSize) { this.boardSize = boardSize; boardStatuses = new Type[boardSize, boardSize]; for (int i = 0; i < boardSize; i++) { for (int j = 0; j < boardSize; j++) { boardStatuses[i, j] = initValue; } } }
static SerializerHost2008() { Type[,] array = new Type[1, 2]; Type[,] array2 = array; Type typeFromHandle = typeof(Report); array2[0, 0] = typeFromHandle; Type[,] array3 = array; Type typeFromHandle2 = typeof(Report2008); array3[0, 1] = typeFromHandle2; SerializerHost2008.m_substituteTypes = array; }
private static void InitializeControllersArray() { emitterControllers = new Type[Enum.GetNames(typeof(BarrelType)).Length, Enum.GetNames(typeof(MagazineType)).Length]; // Pistol controllers emitterControllers[(int)BarrelType.PISTOL, (int)MagazineType.METAL] = typeof(MetalPistolEmitterController); // Machine Gun controllers emitterControllers[(int)BarrelType.MACHINE_GUN, (int)MagazineType.METAL] = typeof(MetalMachineGunEmitterController); // Shotgun controllers // Rail Gun controllers // Grenade Launcher controllers }
public static Type[,] DeepCopy <Type>(Type[,] source) { Type[,] copy = new Type[source.GetLength(0), source.GetLength(1)]; for (int i = 0; i < copy.GetLength(0); i++) { for (int j = 0; j < copy.GetLength(1); j++) { copy[i, j] = source[i, j]; } } return(copy); }
static ImplicitConverter() { // Create a table with all the primitive types Type[] types = { typeof(char), typeof(byte), typeof(sbyte), typeof(Int16), typeof(UInt16), typeof(Int32), typeof(UInt32), typeof(Int64), typeof(UInt64), typeof(float), typeof(double) }; OurBinaryTypes = types; Type[,] table = new Type[types.Length, types.Length]; OurBinaryResultTable = table; FillIdentities(types, table); // Fill the table AddEntry(typeof(UInt32), typeof(UInt64), typeof(UInt64)); AddEntry(typeof(Int32), typeof(Int64), typeof(Int64)); AddEntry(typeof(UInt32), typeof(Int64), typeof(Int64)); AddEntry(typeof(Int32), typeof(UInt32), typeof(Int64)); AddEntry(typeof(UInt32), typeof(float), typeof(float)); AddEntry(typeof(UInt32), typeof(double), typeof(double)); AddEntry(typeof(Int32), typeof(float), typeof(float)); AddEntry(typeof(Int32), typeof(double), typeof(double)); AddEntry(typeof(Int64), typeof(float), typeof(float)); AddEntry(typeof(Int64), typeof(double), typeof(double)); AddEntry(typeof(UInt64), typeof(float), typeof(float)); AddEntry(typeof(UInt64), typeof(double), typeof(double)); AddEntry(typeof(float), typeof(double), typeof(double)); // Byte AddEntry(typeof(byte), typeof(byte), typeof(Int32)); AddEntry(typeof(byte), typeof(sbyte), typeof(Int32)); AddEntry(typeof(byte), typeof(Int16), typeof(Int32)); AddEntry(typeof(byte), typeof(UInt16), typeof(Int32)); AddEntry(typeof(byte), typeof(Int32), typeof(Int32)); AddEntry(typeof(byte), typeof(UInt32), typeof(UInt32)); AddEntry(typeof(byte), typeof(Int64), typeof(Int64)); AddEntry(typeof(byte), typeof(UInt64), typeof(UInt64)); AddEntry(typeof(byte), typeof(float), typeof(float)); AddEntry(typeof(byte), typeof(double), typeof(double)); // SByte AddEntry(typeof(sbyte), typeof(sbyte), typeof(Int32)); AddEntry(typeof(sbyte), typeof(Int16), typeof(Int32)); AddEntry(typeof(sbyte), typeof(UInt16), typeof(Int32)); AddEntry(typeof(sbyte), typeof(Int32), typeof(Int32)); AddEntry(typeof(sbyte), typeof(UInt32), typeof(long)); AddEntry(typeof(sbyte), typeof(Int64), typeof(Int64)); //invalid -- AddEntry(GetType(SByte), GetType(UInt64), GetType(UInt64)) AddEntry(typeof(sbyte), typeof(float), typeof(float)); AddEntry(typeof(sbyte), typeof(double), typeof(double)); // int16 AddEntry(typeof(Int16), typeof(Int16), typeof(Int32)); AddEntry(typeof(Int16), typeof(UInt16), typeof(Int32)); AddEntry(typeof(Int16), typeof(Int32), typeof(Int32)); AddEntry(typeof(Int16), typeof(UInt32), typeof(long)); AddEntry(typeof(Int16), typeof(Int64), typeof(Int64)); //invalid -- AddEntry(GetType(Int16), GetType(UInt64), GetType(UInt64)) AddEntry(typeof(Int16), typeof(float), typeof(float)); AddEntry(typeof(Int16), typeof(double), typeof(double)); // Uint16 AddEntry(typeof(UInt16), typeof(UInt16), typeof(Int32)); AddEntry(typeof(UInt16), typeof(Int16), typeof(Int32)); AddEntry(typeof(UInt16), typeof(Int32), typeof(Int32)); AddEntry(typeof(UInt16), typeof(UInt32), typeof(UInt32)); AddEntry(typeof(UInt16), typeof(Int64), typeof(Int64)); AddEntry(typeof(UInt16), typeof(UInt64), typeof(UInt64)); AddEntry(typeof(UInt16), typeof(float), typeof(float)); AddEntry(typeof(UInt16), typeof(double), typeof(double)); // Char AddEntry(typeof(char), typeof(char), typeof(Int32)); AddEntry(typeof(char), typeof(UInt16), typeof(UInt16)); AddEntry(typeof(char), typeof(Int32), typeof(Int32)); AddEntry(typeof(char), typeof(UInt32), typeof(UInt32)); AddEntry(typeof(char), typeof(Int64), typeof(Int64)); AddEntry(typeof(char), typeof(UInt64), typeof(UInt64)); AddEntry(typeof(char), typeof(float), typeof(float)); AddEntry(typeof(char), typeof(double), typeof(double)); }