using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _9
{
public class NineChess
{
public int[,] chessBoard = new int[3, 3];
public int[] w=new int[2];
public int[] w2 = new int[27];
//棋盘
public int[,] ChessBoard
{
get
{
return chessBoard;
}
set
{
chessBoard = value;
}
}
public bool If(int r)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
if (r == chessBoard[i,j])
{
return false;
}
}
}
return true;
}
public int[] win(int[,] x)
{
w[0]=x[0, 0]*x[0, 1]*x[0, 2]+x[1, 0]*x[1, 1]*x[1, 2]+x[2, 0]*x[2, 1]*x[2, 2];
w[1]=x[0, 0]*x[1, 0]*x[2, 0]+x[0, 1]*x[1, 1]*x[2, 1]+x[0, 2]*x[1, 2]*x[2, 2];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Console.Write(x[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
Console.WriteLine("人值" + w[0]);
Console.WriteLine("电脑值" + w[1]);
return w;
}
public string[] StrMax(int[,] c)
{
string[] str = new string[27];
int index = 0;
for (int a = 0; a < 3; a++)
{
for (int b = 0; b < 3; b++)
{
str[index++] += c[a, b].ToString() + " ";
//Console.Write(c[a, b] + " ");
}
//Console.WriteLine();
}
Console.WriteLine();
return str;
}
public int[,] Switch(int[] set,int a,int b)
{
int[,] chessBoard = new int[3, 3];
int index = 0;
int t = 0;
t=set[a];
set[a] = set[b];
set[b] = t;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
chessBoard[i, j] = set[index++];
}
}
return chessBoard;
}
public int[] Switch2(int[,] set)
{
int index = 0;
int[] set2 = new int[9];
int t = 0;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
set2[index++] = set[i,j];
}
}
return set2;
}
public int[] Switch3()
{
int[] set2 = new int[9];
for (int i = 0; i < 9; i++)
{
set2[i] = i+1;
}
return set2;
}
//走下一步
public int[] Next()
{
//你需要在这个方法里面完成一步,即往当前棋盘上下一步
Random rd = new Random();
int[] w=new int[2];
int[] w2 = new int[100];
int[,] chessBoard = new int[3, 3];
int index = 0;
int index2 = 0;
int[] set = new int[9] {1,2,3,4,5,6,7,8,9 };
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
chessBoard[i, j] = set[index++];
}
}
for (int i = 0; i < 8; i++)
{
for (int j = 8; j >i; j--)
{
index2++;
Console.WriteLine("win最大的下法是第" + index2 + "种");
w = win(chessBoard);
if (w[0] > w[1]) w2[index++] = w[0];
//set = Switch2(chessBoard);
set = Switch3();
chessBoard = Switch(set, i, j);
}
}
int max = 0;
max = w2[0];
int x = 0;
for (int i = 0; i < 27; i++)
{
if (max < w2[i])
{
max = w2[i];
x = i;
}
}
Console.WriteLine("人win最多下法是" + x+" 种");
Console.WriteLine("人win最大值是"+max);
return w2;
}
}
class Program
{
static void Main(string[] args)
{
NineChess nc = new NineChess();
/*int[,] win = new int[3,3];
int max = 0;
win=nc.Next();
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Console.WriteLine(win[i,j]+" ");
}
Console.WriteLine();
}*/
nc.Next();
Console.ReadLine();
}
}
}