/// <summary> /// Adds the new value to board. /// </summary> /// <param name="board">The board.</param> /// <param name="rowsCount">The rows count.</param> /// <param name="columnsCount">The columns count.</param> public void AddNewValueToBoard(ulong[,] board, int rowsCount, int columnsCount) { var random = new Random(); ulong randomValueOf95Percent = 2; ulong randomValueOfTheRest = 4; int random95PercentCheck = 95; // Find all empty slots var emptySlots = new List <Tuple <int, int> >(); for (int row = 0; row < rowsCount; row++) { for (int column = 0; column < columnsCount; column++) { if (board[row, column] == 0) { emptySlots.Add(new Tuple <int, int>(row, column)); } } } // Creates the default random slot int randomSlot = random.Next(0, emptySlots.Count); // Calculates radom slot value ulong value = random.Next(0, 100) < random95PercentCheck ? randomValueOf95Percent : randomValueOfTheRest; // Updates the board with calculated random value board[ emptySlots[randomSlot].Item1, emptySlots[randomSlot].Item2 ] = value; }
static Hash() { rnd = new Random(); boardCodes = new ulong[25, 2, 2]; for (var cell = 0; cell < 25; cell++) { for (var player = 0; player < 2; player++) { for (var piece = 0; piece < 2; piece++) { boardCodes[cell, player, piece] = NextUlong(); } } } cardsCodes = new ulong[Card.Definitions.Length, 2]; for (var card = 0; card < Card.Definitions.Length; card++) { for (var player = 0; player < 2; player++) { cardsCodes[card, player] = NextUlong(); } } playersCodes = new ulong[2]; for (var player = 0; player < 2; player++) { playersCodes[player] = NextUlong(); } }
static void PrintMultiplesOf(ulong n, ulong[,] matrix) { Console.WriteLine($"Multiples of {n}:"); for (var i = 0; i < matrix.GetLength(0); i++) { Console.Write($"Row {i}: "); var max = ulong.MinValue; for (var j = 0; j < matrix.GetLength(1); j++) { var m = matrix[i, j]; if (m % n == 0) { Console.Write($"{m} "); max = Math.Max(max, m); } } if (max > ulong.MinValue) { Console.WriteLine($"(max: {max})"); } else { Console.WriteLine($"no multiples of {n}"); } } Console.WriteLine(); }
public static ulong[,] MatrixMul(this ulong[,] arr, ulong[,] x, ulong mod) { var a0 = arr.GetLength(0); var a1 = arr.GetLength(1); var b0 = x.GetLength(0); var b1 = x.GetLength(1); if (a1 != b0) { throw new InvalidOperationException(); } var result = new ulong[a0, b1]; for (var i = 0; i < a0; i++) { for (var j = 0; j < b1; j++) { var s = 0ul; for (var k = 0; k < a1; k++) { s = (s + (arr[i, k] * x[k, j] % mod)) % mod; } result[i, j] = s; } } return(result); }
public gameClass() //creating game obj { this.Matrix = new ulong[4, 4]; this.Columns = this.Matrix.GetLength(1); this.Rows = this.Matrix.GetLength(0); this.points = 0; }
private static ulong LettersOfNumber(ulong num, ulong[,] bases) { ulong count = 0; if (num == 1000) { count = 11; } else { ulong tempnum = num % 100; if (tempnum < 20) { count += bases[tempnum, 0]; } else { count += bases[num % 10, 0] + bases[(num / 10) % 10, 1]; } if (num > 99) { count += bases[(num / 100), 0] + (ulong)(7 + ((tempnum == 0) ? 0 : 3)); } } return(count); }
private static ulong FindPathDp(int[] arr, ulong[,] memo, int n) { FillBottomLeftToTopRightDiagonal(arr, memo, n); var offset = 1; for (var i = n - 1 - offset; i >= 0; i--) // Top right most row and column cell is already filled, so we start with the cell below that. { for (var j = i + 1; j < n; j++) { var dayValue = i + 1; // Because our array index starts with is 0 when day should be 1 // Value of treat for the next day ulong topCell = memo[i + 1, j]; ulong leftCell = memo[i, j - 1]; ulong value; if (topCell > leftCell) { var currentDayTreatValue = arr[i] * dayValue; value = topCell + (ulong)currentDayTreatValue; } else { var currentDayTreatValue = arr[j] * dayValue; value = leftCell + (ulong)currentDayTreatValue; } memo[i, j] = value; } } return(memo[0, n - offset]); }
public Game() { Board = new ulong[4, 4]; //Gives the dimensions of our game board, original 2048 was 4x4 Rows = Board.GetLength(0); Cols = Board.GetLength(1); Score = 0; }
static void BuildCache() { checked { d = new ulong[max, max]; for (int i = 0; i < max; i++) { for (int j = i; j < max; j++) { if (i == 0) { d[i, j] = 1; d[j, i] = 1; } else if (i == j) { d[i, i] = d[i - 1, i]; } else { d[i, j] = (d[i - 1, j] + d[i, j - 1]) % dv; d[j, i] = d[i, j]; } } } } }
/** * Constructor */ public Cache() { //initialize time cycle = 0; //size of a set in bytes int set_size = Config.proc.block_size * Config.proc.cache_assoc; //total number of sets Debug.Assert(Config.proc.cache_size % set_size == 0); set_max = (uint)(Config.proc.cache_size / set_size); //components cache = new ulong[set_max, Config.proc.cache_assoc]; timestamp = new ulong[set_max, Config.proc.cache_assoc]; dirty = new bool[set_max, Config.proc.cache_assoc]; core_id = new ulong[set_max, Config.proc.cache_assoc]; //initialize tags for (int i = 0; i < set_max; i++) { for (int j = 0; j < Config.proc.cache_assoc; j++) { cache[i, j] = Proc.NULL_ADDRESS; core_id[i, j] = Proc.NULL_ADDRESS; } } count++; }
public void Apply(GameState gameState) { IrrevStates = gameState.IrrevStates.Select(s => s.Copy()).ToList(); Pieces = (ulong[, ])gameState.Pieces.Clone(); Occupancy = (ulong[])gameState.Occupancy.Clone(); Turn = gameState.Turn; }
public ulong[,] total_req_per_procbank; //total number of requests per processor for each bank [proc, bank] public MemSchedStat(int proc_max, Bank[] bank, int bank_max) { //collect stats is_collect_stat = new bool[Config.N]; for (int p = 0; p < Config.N; p++) { is_collect_stat[p] = true; } //components this.bank = bank; this.bank_max = bank_max; //this.proc_max = proc_max; //other stats tick_load_per_proc = new ulong[proc_max]; time_avg_load_per_proc = new double[proc_max]; tick_req = new ulong[proc_max]; tick_req_cnt = new ulong[proc_max]; tick_marked = new ulong[proc_max]; tick_marked_req = new ulong[proc_max]; tick_unmarked = new ulong[proc_max]; tick_unmarked_req = new ulong[proc_max]; total_req_per_procbank = new ulong[proc_max, bank_max]; }
private int toCompare(ulong[,] a, ulong[] b, int i) { if (i >= 0) { if (a[i, 0] < b[0]) { return(1); } if (a[i, 0] > b[0]) { return(-1); } if (a[i, 0] == b[0]) { for (int k = 1; k < a.GetLength(1); k++) { if (a[i, k] + a[i, k - 1] < b[k] + b[k - 1]) { return(1); } if (a[i, k] + a[i, k - 1] > b[k] + b[k - 1]) { return(-1); } if (a[i, k] + a[i, k - 1] == b[k] + b[k - 1]) { continue; } } } } return(0); }
public TranspTable(uint size) { chaves = new ulong[bbConstants.PECAS + 1, 64]; chavesRoque = new ulong[4]; this.size = size; this.tabela = new TranspItem[size]; objLock = new object[(size / 1000) + 1]; for (int i = 0; i < (size / 1000) + 1; i++) { objLock[i] = new object(); } read(); movsBuscados = new List <movBusc> [bbConstants.MAXPLY]; for (int i = 0; i < 4; i++) { lock (lockMove) { movsBuscados[i] = new List <movBusc>(); for (int j = 0; j < bbConstants.MAXPLY; j++) { movBusc movB = new movBusc(); movB.hash = 0; movsBuscados[i].Add(movB); } } } }
public DR() { this.Board = new ulong[4, 4]; this.nRows = this.Board.GetLength(0); this.nCols = this.Board.GetLength(1); this.Score = 0; }
public static bool action(ulong[,] board, movDirection dir, out ulong points) { int Rows = board.GetLength(0); int Columns = board.GetLength(1); bool Updated = false; points = 0; //movement bool inRow = dir == movDirection.Left || dir == movDirection.Right; bool isIncreasing = dir == movDirection.Left || dir == movDirection.Up; int oCount = inRow ? Rows : Columns; int iCount = inRow ? Columns : Rows; int iStart = isIncreasing ? 0 : iCount - 1; int iEnd = isIncreasing ? iCount - 1 : 0; Func <int, int> drop = isIncreasing? new Func <int, int>(iIndex => iIndex - 1) : new Func <int, int>(iIndex => iIndex + 1); Func <int, int> reverseDrop = isIncreasing ? new Func <int, int>(iIndex => iIndex + 1) : new Func <int, int>(iIndex => iIndex - 1); Func <ulong[, ], int, int, ulong> Value = inRow ? new Func <ulong[, ], int, int, ulong>((x, i, j) => x[i, j]) : new Func <ulong[, ], int, int, ulong>((x, i, j) => x[j, i]); Func <int, bool> iCondition = index => Math.Min(iStart, iEnd) <= index && index <= Math.Max(iStart, iEnd); Action <ulong[, ], int, int, ulong> setValue = inRow ? new Action <ulong[, ], int, int, ulong>((x, i, j, v) => x[i, j] = v) : new Action <ulong[, ], int, int, ulong>((x, i, j, v) => x[j, i] = v); for (int i = 0; i < oCount; i++) { for (int j = iStart; iCondition(j); j = reverseDrop(j)) { int newJ = j; if (Value(board, i, j) == 0) { continue; } do { newJ = drop(newJ); }while (iCondition(newJ) && Value(board, i, newJ) == 0); //merge matching pair if (iCondition(newJ) && Value(board, i, newJ) == Value(board, i, j)) { ulong newValue = Value(board, i, newJ) * 2; setValue(board, i, newJ, newValue); setValue(board, i, j, 0); Updated = true; points += newValue; } else //stack along if not suitable to merge { newJ = reverseDrop(newJ); if (newJ != j) { Updated = true; } ulong value = Value(board, i, j); setValue(board, i, j, 0); setValue(board, i, newJ, value); } } } return(Updated); }
private void main() { int[] HW = Console.ReadLine().Split().Select(int.Parse).ToArray(); H = HW[0]; W = HW[1]; a = new int[H + 2, W + 2]; memo = new ulong[1002, 1002]; for (int y = 0; y < H; y++) { int[] row = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int x = 0; x < W; x++) { a[y + 1, x + 1] = row[x]; } } ulong ans = 0; for (int y = 1; y <= H; y++) { for (int x = 1; x <= W; x++) { ans = (ans + rec(y, x)) % MOD; } } Console.WriteLine(ans); }
private static void Last_block_proc(ulong[,] state, byte[] messageB, ushort rateInBytes) { var delta = (ushort)(rateInBytes - messageB.Length); var padMessage = new byte[rateInBytes]; var pos = 0; foreach (var t in messageB) { padMessage[pos] = t; ++pos; } if (delta == 1) { padMessage[pos] = 0x86; } else { padMessage[pos] = 0x06; delta -= 2; while (delta > 0) { padMessage[pos + delta] = 0x00; --delta; } padMessage[padMessage.Length - 1] = 0x80; } State_Change(state, padMessage, rateInBytes); }
internal Multiplication(MainForm UseForm) { MForm = UseForm; M = new ulong[Integer.DigitArraySize, Integer.DigitArraySize]; Scratch = new ulong[Integer.DigitArraySize]; }
private static byte[] Squeezing(ulong[,] state, ushort rateInBytes) { var hash = new byte[rateInBytes]; var cur = 0; for (byte jb = 0; jb < 5; ++jb) { for (byte ib = 0; ib < 5; ++ib) { var pos = ib + jb * 5; if (pos < rateInBytes / StateWidthInBytes) { var temp = BitConverter.GetBytes(state[ib, jb]); for (var j = 0; j < 8; ++j) { hash[cur + j] = temp[j]; } cur += 8; } } } return(hash); }
private static void State_Change(ulong[,] state, byte[] message, ushort rateInBytes) { for (byte ib = 0; ib < 5; ++ib) { for (byte jb = 0; jb < 5; ++jb) { var pos = ib + jb * 5; if (pos < rateInBytes / StateWidthInBytes) { pos *= StateWidthInBytes; for (byte i = 0; i < StateWidthInBytes; ++i) { state[ib, jb] ^= (ulong)message[pos + i] << (i * 8); } } else { break; } } } for (byte i = 0; i < RoundsNumber; i++) { state = Round(state, Rc[i]); } }
static ulong[,] ArraySort(ulong[,] maxcounts, int mode) //Mode: [0]Sort by step number; [1]Sort by number magnitude { ulong[,] temp = new ulong[10, 2]; int maxval = 0, count = 0, index = 0; ulong num = 0; for (int x = 0; x < 10; x++) { for (int i = 0; i < 10; i++) { if (maxcounts[i, mode] >= (ulong)maxval) { maxval = (int)maxcounts[i, mode]; count = (int)maxcounts[i, 0]; num = maxcounts[i, 1]; index = i; } } temp[x, 0] = (ulong)count; temp[x, 1] = num; maxcounts[index, 0] = 0; maxcounts[index, 1] = 0; maxval = 0; } return(temp); }
public Game() { Board = new ulong[4, 4]; nRows = Board.GetLength(0); nCols = Board.GetLength(1); Score = 0; }
//constructor public MemCtrl(uint rmax, DDR3DRAM ddr3) { this.cid = cmax; cmax++; //states this.rmax = rmax; this.bmax = ddr3.BANK_MAX; //DDR3 timing = ddr3.timing; this.col_max = ddr3.COL_MAX; this.row_size = ddr3.COL_MAX * ddr3.CHANNEL_WIDTH; //components chan = new Channel(this, rmax, ddr3.BANK_MAX); //row-hit finder rh_finder = new RowHitFinder(this); //queues int readq_max = Config.mctrl.readq_max_per_bank; writeq_max = (int)this.rmax * (int)this.bmax * Config.mctrl.writeq_max_per_bank; readqs = new List <Req> [rmax, bmax]; writeqs = new List <Req> [rmax, bmax]; mctrl_writeq = new List <Req>(writeq_max); inflightqs = new List <Req> [rmax, bmax]; cmdqs = new List <Cmd> [rmax, bmax]; for (uint r = 0; r < rmax; r++) { for (uint b = 0; b < bmax; b++) { readqs[r, b] = new List <Req>(readq_max); writeqs[r, b] = new List <Req>(writeq_max); inflightqs[r, b] = new List <Req>(INFLIGHTQ_MAX); cmdqs[r, b] = new List <Cmd>(CMDQ_MAX); } } bus_q = new List <BusTransaction>((int)BUS_TRANSACTIONS_MAX); //stats rload_per_proc = new uint[Config.N]; rload_per_procrankbank = new uint[Config.N, rmax, bmax]; shadow_rowid_per_procrankbank = new ulong[Config.N, rmax, bmax]; rowid_per_procrankbank = new ulong[rmax, bmax]; pid_rowid_per_procrankbank = new int[rmax, bmax]; wload_per_proc = new uint[Config.N]; wload_per_procrankbank = new uint[Config.N, rmax, bmax]; //writeback throttler wbthrottle = Activator.CreateInstance(Config.sched.typeof_wbthrottle_algo) as WBThrottle; total_queueing_latency = new ulong[Config.N]; curr_proc = new int[bmax]; }
public static Move getAMove(bool isWhitesTurn) { //Create the resulting move Move result = new Move(); //Get first player identity and board identity first = Program.getFirstPlayer(); Board board = Program.getBoard(); //Convert to AISpace ulong[,] AISQUARES = { { 1, 2, 4, 8, 16, 32, 64, 128 }, { 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }, { 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608 }, { 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648 }, { 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888 }, { 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328 }, { 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968 }, { 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904, 9223372036854775808 } }; ulong black = 0; ulong white = 0; for (uint i = 0; i < 8; i++) { for (uint j = 0; j < 8; j++) { if (board.blackRows[i] % board.COLUMNS[j] == 0) { black += AISQUARES[i, j]; } if (board.whiteRows[i] % board.COLUMNS[j] == 0) { white += AISQUARES[i, j]; } } } //Get the move from the AI DLL AIMove nextMove = AIGetMove(board.blackCount, board.whiteCount, black, white, isWhitesTurn, 0); //Convert the AIMove to a Move class result.Begin.X = checked ((int)nextMove.row); result.Begin.Y = checked ((int)nextMove.col); if (isWhitesTurn) { result.End.X = checked ((int)nextMove.row + 1); } else { result.End.X = checked ((int)nextMove.row - 1); } result.End.Y = checked ((int)(nextMove.col + nextMove.target - 1)); //Return the result return(result); }
/// <summary> /// 矩阵法 /// </summary> /// <param name="n"></param> /// <returns></returns> static ulong F3(int n) { ulong[,] a = new ulong[2, 2] { { 1, 1 }, { 1, 0 } }; ulong[,] b = MatirxPower(a, n); return(b[1, 0]); }
public BitMatrix(int m, int n) { M = m; N = n; internalM_ = 1 + M / 8; internalN_ = 1 + N / 8; internalMatrix_ = new ulong[internalM_, internalN_]; }
private ulong[,] Keccackf(ulong[,] A) { for (int i = 0; i < n; i++) { A = roundB(A, RC[i]); } return(A); }
/// <summary> /// 矩阵法 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int FibByJZ(int n) { ulong[,] a = new ulong[2, 2] { { 1, 1 }, { 1, 0 } }; ulong[,] b = MatirxPower(a, n); return((int)b[1, 0]); }
/// <summary> /// Initializes a new instance of the <see cref="Game" /> class. /// </summary> public Game(IServiceProvider serviceProvider) { gameAlgorithm = serviceProvider.GetService <IGameAlgorithm>(); this.Board = new ulong[4, 4]; this.rowsCount = this.Board.GetLength(0); this.columnsCount = this.Board.GetLength(1); this.Score = 0; }