C # implement code and effect of L-type chess and card coverage

Source: Internet
Author: User

// Main

Copy codeThe Code is as follows: using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;

Namespace ChessBoard
{
Class Program
{
// Who can teach me English? What are the mistakes in English grammar,
Static void Main (string [] args)
{
Function obj = new Function ();

Console. WriteLine ("Please intput CheseBoard Size (2 ^ size ):");
Int size = (int) Math. Pow (2, Convert. ToInt32 (Console. ReadLine ()));
If (size! = 1)
{
Lelecolor FC = Console. ForegroundColor;
// String [] Color = {"Black", "DarkBlue", "DarkGreen", "DarkCyan", "Gray ",
// "DarkRed", "DarkMagenta", "DarkYellow", "Red ",
// "DarkGray", "Blue", "Green", "Cyan", "Magenta ",
// "Yellow", "White "};
String [,] Board = new string [size, size];

// Do you know?
String [] Colors = ConsoleColor. GetNames (typeof (ConsoleColor ));

Console. WriteLine ("please input special grid position (row and col ):");
Int rows = Convert. ToInt32 (Console. ReadLine ());
Int cols = Convert. ToInt32 (Console. ReadLine ());

Obj. CheseBoard (Board, size, rows, cols );

For (int r = 0; r <Board. GetLength (0); r ++)
{
For (int c = 0; c <Board. GetLength (1); c ++)
{
Int Value = Convert. ToInt32 (Board [r, c]. ToString ());
If (Value> 0)
{
If (Value> 15)
{
Value % = 15;
}
If (Value % = 15) = 0)
{
Value + = 1;
}
Console. ForegroundColor = (ConsoleColor) Enum. Parse (typeof (ConsoleColor), Colors [Value]);
}
Console. Write (Board [r, c] + "");
// Console. ForegroundColor = FC;
Console. ResetColor ();
}
Console. WriteLine ();
}
}
Else
{
Console. WriteLine ("Bugs Bug! ! ! ");
}
Console. ReadKey ();
}
}
}

// Class

Copy codeThe Code is as follows: using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;

Namespace ChessBoard
{
Class Function
{
/// <Summary>
/// Initialize the L-type card
/// </Summary>
Private int LDominoNumberInitial = 0;

/// <Summary>
/// L-type bone board coverage
/// </Summary>
/// <Param name = "Board"> </param>
/// <Param name = "size"> </param>
/// <Param name = "row"> </param>
/// <Param name = "col"> </param>
Public void CheseBoard (string [,] Board, int size, int row, int col)
{
Int InitialRow = 0;
Int InitialCol = 0;
// Invalid input
If (row> size-1 | col> size-1)
{
Console. WriteLine ("Error !!!!!!!!!! ");
}
// The chessboard has only one grid.
Else if (size = 1)
{
Console. WriteLine (Board [row, col] = "-1 ");
}
Else
{
Board [row, col] = "-1 ";
DivisionBoard (Board, InitialRow, InitialCol, row, col, size );
}
}

/// <Summary>
/// The large checker 4 is divided into small checkerboard, which has no special position (as a special position)
/// Then divide each small 4 again... there is only one grid.
/// </Summary>
/// <Param name = "Board"> </param>
/// <Param name = "InitialRow"> </param>
/// <Param name = "InitialCol"> </param>
/// <Param name = "row"> </param>
/// <Param name = "col"> </param>
/// <Param name = "size"> </param>
Public void DivisionBoard (string [,] Board, int InitialRow, int InitialCol, int row, int col, int size)
{
If (size = 1)
{
Return;
}
// It's Important... copy of the number of global dominoes
Int LDominoNumber = LDominoNumberInitial ++;
// Determine the Boundary Value of a special position
Size/= 2;
// Left up
If (row <InitialRow + size & col <InitialCol + size)
{
// Special location inside
DivisionBoard (Board, InitialRow, InitialCol, row, col, size );
}
Else
{
// Not in it. Put a corner of the string here to prepare for the next recursion ..
If (LDominoNumber <10)
{
Board [InitialRow + size-1, InitialCol + size-1] = "0" + LDominoNumber. ToString ();
}
Else
{
Board [InitialRow + size-1, InitialCol + size-1] = LDominoNumber. ToString ();
}
// Console. ForegroundColor = FC;
// The top left corner
DivisionBoard (Board, InitialRow, InitialCol, InitialRow + size-1, InitialCol + size-1, size );
}
// Right up
If (row <InitialRow + size & col> = InitialCol + size)
{
DivisionBoard (Board, InitialRow, InitialCol + size, row, col, size );
}
Else
{
If (LDominoNumber <10)
{
Board [InitialRow + size-1, InitialCol + size] = "0" + LDominoNumber. ToString ();
}
Else
{
Board [InitialRow + size-1, InitialCol + size] = LDominoNumber. ToString ();
}
DivisionBoard (Board, InitialRow, InitialCol + size, InitialRow + size-1, InitialCol + size, size );
}
// Left down
If (row> = InitialRow + size & col <InitialCol + size)
{
DivisionBoard (Board, InitialRow + size, InitialCol, row, col, size );
}
Else
{
If (LDominoNumber <10)
{
Board [InitialRow + size, InitialCol + size-1] = "0" + LDominoNumber. ToString ();
}
Else
{
Board [InitialRow + size, InitialCol + size-1] = LDominoNumber. ToString ();
}
DivisionBoard (Board, InitialRow + size, InitialCol, InitialRow + size, InitialCol + size-1, size );
}
// Right down
If (row> = InitialRow + size & col> = InitialCol + size)
{
DivisionBoard (Board, InitialRow + size, InitialCol + size, row, col, size );
}
Else
{
If (LDominoNumber <10)
{
Board [InitialRow + size, InitialCol + size] = "0" + LDominoNumber. ToString ();
}
Else
{
Board [InitialRow + size, InitialCol + size] = LDominoNumber. ToString ();
}
DivisionBoard (Board, InitialRow + size, InitialCol + size, InitialRow + size, InitialCol + size, size );
}
}
}
}

// Program running result

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.