Skip to content

Instantly share code, notes, and snippets.

@laoshanlungo
Created June 20, 2018 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laoshanlungo/fa59671069ba9fca5ac5a5d51c8aaf30 to your computer and use it in GitHub Desktop.
Save laoshanlungo/fa59671069ba9fca5ac5a5d51c8aaf30 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prog3SchachGui
{
public enum ChessPieceType
{
King,
Queen,
Rook,
Bishop,
Knight,
Pawn,
None
}
public enum ChessPieceColor
{
White,
Black
}
public class Board
{
public const int size = 64;
internal Square[] Squares;
internal Board(ChessPieceColor sColor, ChessPieceColor pColor, ChessPieceType type)
{
Squares = new Square[size];
for (byte i = 0; i < 8; i++)
{
if(i%2 == 0)
{
Squares[i] = new Square(ChessPieceColor.Black, pColor, type);
}
if (i % 2 != 0)
{
Squares[i] = new Square(ChessPieceColor.White, pColor, type);
}
}
for (byte i = 8; i < 16; i++)
{
if (i % 2 == 0)
{
Squares[i] = new Square(ChessPieceColor.White, pColor, type);
}
if (i % 2 != 0)
{
Squares[i] = new Square(ChessPieceColor.Black, pColor, type);
}
Squares[i].Piece.PieceType = ChessPieceType.Pawn;
Squares[i].Piece.PieceColor = ChessPieceColor.White;
}
for (byte i = 16; i < 24; i++)
{
if (i % 2 == 0)
{
Squares[i] = new Square(ChessPieceColor.Black, pColor, type);
}
if (i % 2 != 0)
{
Squares[i] = new Square(ChessPieceColor.White, pColor, type);
}
}
for (byte i = 24; i < 32; i++)
{
if (i % 2 == 0)
{
Squares[i] = new Square(ChessPieceColor.White, pColor, type);
}
if (i % 2 != 0)
{
Squares[i] = new Square(ChessPieceColor.Black, pColor, type);
}
}
for (byte i = 32; i < 40; i++)
{
if (i % 2 == 0)
{
Squares[i] = new Square(ChessPieceColor.Black, pColor, type);
}
if (i % 2 != 0)
{
Squares[i] = new Square(ChessPieceColor.White, pColor, type);
}
}
for (byte i = 40; i < 48; i++)
{
if (i % 2 == 0)
{
Squares[i] = new Square(ChessPieceColor.White, pColor, type);
}
if (i % 2 != 0)
{
Squares[i] = new Square(ChessPieceColor.Black, pColor, type);
}
}
for (byte i = 48; i < 56; i++)
{
if (i % 2 == 0)
{
Squares[i] = new Square(ChessPieceColor.Black, pColor, type);
}
if (i % 2 != 0)
{
Squares[i] = new Square(ChessPieceColor.White, pColor, type);
}
Squares[i].Piece.PieceType = ChessPieceType.Pawn;
Squares[i].Piece.PieceColor = ChessPieceColor.Black;
}
for (byte i = 56; i < 64; i++)
{
if (i % 2 == 0)
{
Squares[i] = new Square(ChessPieceColor.White, pColor, type);
}
if (i % 2 != 0)
{
Squares[i] = new Square(ChessPieceColor.Black, pColor, type);
}
}
Squares[0].Piece.PieceType = ChessPieceType.Rook;
Squares[0].Piece.PieceColor = ChessPieceColor.White;
Squares[1].Piece.PieceType = ChessPieceType.Knight;
Squares[1].Piece.PieceColor = ChessPieceColor.White;
Squares[2].Piece.PieceType = ChessPieceType.Bishop;
Squares[2].Piece.PieceColor = ChessPieceColor.White;
Squares[3].Piece.PieceType = ChessPieceType.Queen;
Squares[3].Piece.PieceColor = ChessPieceColor.White;
Squares[4].Piece.PieceType = ChessPieceType.King;
Squares[4].Piece.PieceColor = ChessPieceColor.White;
Squares[5].Piece.PieceType = ChessPieceType.Bishop;
Squares[5].Piece.PieceColor = ChessPieceColor.White;
Squares[6].Piece.PieceType = ChessPieceType.Knight;
Squares[6].Piece.PieceColor = ChessPieceColor.White;
Squares[7].Piece.PieceType = ChessPieceType.Rook;
Squares[7].Piece.PieceColor = ChessPieceColor.White;
Squares[56].Piece.PieceType = ChessPieceType.Rook;
Squares[56].Piece.PieceColor = ChessPieceColor.White;
Squares[57].Piece.PieceType = ChessPieceType.Knight;
Squares[57].Piece.PieceColor = ChessPieceColor.White;
Squares[58].Piece.PieceType = ChessPieceType.Bishop;
Squares[58].Piece.PieceColor = ChessPieceColor.White;
Squares[59].Piece.PieceType = ChessPieceType.Queen;
Squares[59].Piece.PieceColor = ChessPieceColor.White;
Squares[60].Piece.PieceType = ChessPieceType.King;
Squares[60].Piece.PieceColor = ChessPieceColor.White;
Squares[61].Piece.PieceType = ChessPieceType.Bishop;
Squares[61].Piece.PieceColor = ChessPieceColor.White;
Squares[62].Piece.PieceType = ChessPieceType.Knight;
Squares[62].Piece.PieceColor = ChessPieceColor.White;
Squares[63].Piece.PieceType = ChessPieceType.Rook;
Squares[63].Piece.PieceColor = ChessPieceColor.White;
}
}
internal struct Square
{
internal Piece Piece;
internal ChessPieceColor color;
internal Square(ChessPieceColor sColor, ChessPieceColor pColor, ChessPieceType type)
{
Piece = new Piece(type, pColor);
color = sColor;
}
}
internal sealed class Piece
{
internal ChessPieceColor PieceColor;
internal ChessPieceType PieceType;
public Piece(ChessPieceType chessPiece, ChessPieceColor ChessPieceColor)
{
PieceType = chessPiece;
PieceColor = ChessPieceColor;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment