当前位置:网站首页>2048 project realization
2048 project realization
2022-07-05 06:23:00 【mentalps】
1 2048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2048
{
public class MatrixOperation
{
// Calculate the smoothness and connectivity of the matrix
public int[] SmoothAndNum(int[,] matrix)
{
int[,] matrixIndex = new int[5, 5];
int num = 0;
int smooth = 0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
int[] vs1 = MatrixMove(matrix, i, j, 1, ref matrixIndex);
int[] vs2 = MatrixMove(matrix, i, j, 2, ref matrixIndex);
int[] vs3 = MatrixMove(matrix, i, j, 3, ref matrixIndex);
smooth = smooth - vs1[0] - vs2[0] - vs3[0];
num = num + vs1[1] + vs2[1] + vs3[1];
}
}
return new int[2] {
smooth, num };
}
// List all possible filling combinations
//public List<List<int>> AllComb(int max,int min,int num)
// {
// List<int> comb = new List<int>();
// return;
// }
public static int[] MatrixMove(int[,] matrix, int x, int y, int z, ref int[,] matrixIndex)
{
int num = 0;
int smooth = 0;
switch (z)
{
case 1:
if (x + 1 <= matrix.GetUpperBound(1))
{
smooth = (int)Math.Abs(Math.Log(matrix[x, y], 2) - Math.Log(matrix[x + 1, y], 2));
if (smooth == 0)
{
if (matrixIndex[x, y] == 0)
{
matrixIndex[x, y] = 1;
num = num + 1;
}
if (matrixIndex[x + 1, y] == 0)
{
matrixIndex[x + 1, y] = 1;
num = num + 1;
}
}
}
else
{
smooth = 0;
}
break;
case 2:
if ((x + 1 <= matrix.GetUpperBound(1)) && (y + 1 <= matrix.GetUpperBound(0)))
{
smooth = (int)Math.Abs(Math.Log(matrix[x, y], 2) - Math.Log(matrix[x + 1, y + 1], 2));
if (smooth == 0)
{
if (matrixIndex[x, y] == 0)
{
matrixIndex[x, y] = 1;
num = num + 1;
}
if (matrixIndex[x + 1, y + 1] == 0)
{
matrixIndex[x + 1, y + 1] = 1;
num = num + 1;
}
}
}
else
{
smooth = 0;
}
break;
case 3:
if (y + 1 <= matrix.GetUpperBound(0))
{
smooth = (int)Math.Abs(Math.Log(matrix[x, y], 2) - Math.Log(matrix[x, y + 1], 2));
if (smooth == 0)
{
if (matrixIndex[x, y] == 0)
{
matrixIndex[x, y] = 1;
num = num + 1;
}
if (matrixIndex[x, y + 1] == 0)
{
matrixIndex[x, y + 1] = 1;
num = num + 1;
}
}
}
else
{
smooth = 0;
}
break;
}
return new int[2] {
smooth, num };
}
public int[,] FillMatrix(int[,] matrix)
{
List<Tuple<int, int>> fillSteps = new List<Tuple<int, int>>();
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (matrix[i, j] == 0)
{
Tuple<int, int> pos = new Tuple<int, int>(i, j);
fillSteps.Add(pos);
}
}
}
return matrix;
}
// total: Number to fill
public static int [] AllComb(int total,int [] nums,int start, ref List<int []> all_list ,int [] all)
{
if (start < total) {
for (int i = 0; i < nums.Length; i++)
{
all[start] = nums[i];
AllComb(total, nums, start+1,ref all_list,all);
int[] b = new int[total];
Array.Copy(all, b, total);
all_list.Add(b);
}
return all;
}
else
{
return all;
}
}
static void Main(string[] args)
{
int[] nums = {
2, 4, 8 };
int num = 3;
List<int []> all = new List<int []>();
int[] s = new int[num];
AllComb(3, nums, 0,ref all, s);
for(int i=0;i<all.Count;i++)
{
for(int j=0;j<num;j++)
{
Console.WriteLine(all[i][j]);
}
}
}
}
}
边栏推荐
- NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
- 高斯消元 AcWing 884. 高斯消元解异或線性方程組
- Leetcode backtracking method
- Record the process of configuring nccl and horovod in these two days (original)
- [learning] database: MySQL query conditions have functions that lead to index failure. Establish functional indexes
- 2048项目实现
- Shutter web hardware keyboard monitoring
- MySQL advanced part 1: View
- Filter the numbers and pick out even numbers from several numbers
- Sqlmap tutorial (1)
猜你喜欢
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
MatrixDB v4.5.0 重磅发布,全新推出 MARS2 存储引擎!
Leetcode array operation
MySQL advanced part 2: storage engine
【LeetCode】Easy | 20. Valid parentheses
Leetcode-6111: spiral matrix IV
[moviepy] unable to find a solution for exe
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
SQLMAP使用教程(一)
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
随机推荐
Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a
International Open Source firmware Foundation (osff) organization
Applicable to Net free barcode API [off] - free barcode API for NET [closed]
背包问题 AcWing 9. 分组背包问题
Single chip computer engineering experience - layered idea
3.Oracle-控制文件的管理
New title of module a of "PanYun Cup" secondary vocational network security skills competition
栈 AcWing 3302. 表达式求值
5.Oracle-表空间
Leetcode-3: Longest substring without repeated characters
SQL三种连接:内连接、外连接、交叉连接
高斯消元 AcWing 884. 高斯消元解异或线性方程组
MySQL advanced part 2: storage engine
Leetcode-6111: spiral matrix IV
Leetcode-22: bracket generation
What's wrong with this paragraph that doesn't work? (unresolved)
SQLMAP使用教程(一)
【LeetCode】Day95-有效的数独&矩阵置零
Winter messenger 2
Appium foundation - use the first demo of appium