What is best Python DS to store a chess board?

Hi


In Java, I did a quickie byte[][] 8x8 (code below) to store my chess board with each piece having  a number to determine its type.
What is the best way in Python to do something like this? If I do AI heuristics with recursion, how do I delete objects, boards that have been used? How do I make new objects to be created doing recursion?
What should some of this look like? What might moving a random pawn look like? No heuristics, just a random pawn move and then doing recursion on the new board state? I can perfect the legality code, capturing,  once I might see a few random pawns moving forward 1 or 2 squares into an empty square.
I printed the board in text like . .
rnbqkbnr
........
........
........
........
........
RNBKQBNR

Here is the Java game setup code:
static byte[][] newGame() {
		byte[][] n = new byte[8][8];
		
		//pawn, black pieces right side, locations are [row][column]
		for (int i=0; i<8;i++) n[6][i]=7;
		//pawn, white piece left side, locations are [row][column]
		for (int i=0; i<8;i++) n[1][i]=6;

		//pieces white, black,  0 = empty square		
		
		
		n[0][0]=1; //white rook
		n[0][1]=2; //white knight
		n[0][2]=3; //white bishop
		n[0][3]=4; //white queen
		n[0][4]=5; //white king
		n[0][5]=3; //white bishop
		n[0][6]=2; //white knight
		n[0][7]=1; //white rook
		
		n[7][0]=7+1; //black rook
		n[7][1]=7+2; //black knight
		n[7][2]=7+1; //black bishop
		n[7][3]=7+2; //black queen
		n[7][4]=7+1; //black king
		n[7][5]=7+2; //black bishop
		n[7][6]=7+1; //black knight
		n[7][7]=7+2; //black rook


		return n;
		
	}

Open in new window


Here is code that prints the board state..
public static void printBoard(byte[][] B) {

		for (int x=0; x<8;x++) {
		for (int y=0; y<8;y++) {
			int p = B[y][x];
			boolean printedApiece=false;
			if (p==0) {
				System.out.print(".");
			}
			if (p==1) {
				System.out.print("r");
				printedApiece=true;
			}
			if (p==2) {
				System.out.print("n");
				printedApiece=true;
			}
			if (p==3) {
				System.out.print("b");
				printedApiece=true;
			}
			if (p==4) {
				System.out.print("q");
				printedApiece=true;
			}
			if (p==5) {
				System.out.print("k");
				printedApiece=true;
			}
			if (p==6) {
				System.out.print("p");
				printedApiece=true;
			}
			if (p==7) {
				System.out.print("P");
				printedApiece=true;
			}
			if (p==8) {
				System.out.print("R");	
				printedApiece=true;		
			}
			if (p==9) {
				System.out.print("N");
				printedApiece=true;
			}
			if (p==10) {
				System.out.print("B");
				printedApiece=true;
			}
			if (p==11) {
				System.out.print("Q");
				printedApiece=true;
			}
			if (p==12) {
				System.out.print("K");
				printedApiece=true;
			}			
			if (p==13) {
				System.out.print("R");
				printedApiece=true;
			}
		}//y
		System.out.println("");
		}//x
		
	}

Open in new window



Thanks
LVL 1
beavoidAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
"Best" is a subjective term, so you'd have to tell us what you mean by "best".

I don't see why you can't use the same concept in Python--it has arrays as well (but I believe Python calls them "lists").
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.