Skip to main content
added 64 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

Pass the board to the piece you want a move list from.

You’re correct that the board data needs to be where the moves are. But the board is mutable so it’s a poor choice to make into an objects state. So just pass it as a parameter to a method.

Speaking of immutable, pieces don’t need to know where they are. Let the board keep track of that. All the pieces need to know is what their moves are and what their color is.

Let the board be a 2D array of references to such pieces and talking to them will be a snap. Might seem weird until you introduce a null object piece that has blank as its color. Since it generates no moves you can generate your move list simply by looping the board and calling a line like this:

legalMoves.addAll( board[x][y].generateMoves(x, y, board, turn) ); 

Done thisThis way it's polymorphic. You don't have to know what you're talking to. And your objects are immutable. All the stuff that changes gets passed in. Makes debugging a breeze and might even get optimized by the virtual machine.

If you're concerned with history you can use piece types to handle the stranger rules of chess. Kings become MovedKings when moved etc.

I'd go on but I've already talked about chess here a few times. If you're curious this link will get you started.

Pass the board to the piece you want a move list from.

You’re correct that the board data needs to be where the moves are. But the board is mutable so it’s a poor choice to make into an objects state. So just pass it as a parameter to a method.

Speaking of immutable, pieces don’t need to know where they are. Let the board keep track of that. All the pieces need to know is what their moves are and what their color is.

Let the board be a 2D array of references to such pieces and talking to them will be a snap. Might seem weird until you introduce a null object piece that has blank as its color. Since it generates no moves you can generate your move list simply by looping the board and calling a line like this:

legalMoves.addAll( board[x][y].generateMoves(x, y, board, turn) ); 

Done this way your objects are immutable. All the stuff that changes gets passed in. Makes debugging a breeze and might even get optimized by the virtual machine.

If you're concerned with history you can use piece types to handle the stranger rules of chess. Kings become MovedKings when moved etc.

I'd go on but I've already talked about chess here a few times. If you're curious this link will get you started.

Pass the board to the piece you want a move list from.

You’re correct that the board data needs to be where the moves are. But the board is mutable so it’s a poor choice to make into an objects state. So just pass it as a parameter to a method.

Speaking of immutable, pieces don’t need to know where they are. Let the board keep track of that. All the pieces need to know is what their moves are and what their color is.

Let the board be a 2D array of references to such pieces and talking to them will be a snap. Might seem weird until you introduce a null object piece that has blank as its color. Since it generates no moves you can generate your move list simply by looping the board and calling a line like this:

legalMoves.addAll( board[x][y].generateMoves(x, y, board, turn) ); 

This way it's polymorphic. You don't have to know what you're talking to. And your objects are immutable. All the stuff that changes gets passed in. Makes debugging a breeze and might even get optimized by the virtual machine.

If you're concerned with history you can use piece types to handle the stranger rules of chess. Kings become MovedKings when moved etc.

I'd go on but I've already talked about chess here a few times. If you're curious this link will get you started.

added 1 character in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

Pass the board to the piece you want a move list from.

You’re correct that the board data needs to be where the moves are. But the board is mutable so it’s a poor choice to make into an objects state. So just pass it as a parameter to a method.

Speaking of immutable, pieces don’t need to know where they are. Let the board keep track of that. All the pieces need to know is what their moves are and what their color is.

Let the board be a 2D array of references to such pieces and findingtalking to them will be a snap. Might seem weird until you introduce a null object piece that has blank as its color. Since it generates no moves you can generate your move list simply by looping the board and calling a line like this:

legalMoves.addAll( board[x][y].generateMoves(x, y, board, turn) ); 

Done this way your objects are immutable. All the stuff that changes gets passed in. Makes debugging a breeze and might even get optimized by the virtual machine.

If you're concerned with history you can use piece types to handle the stranger rules of chess. Kings become MovedKings when moved etc.

I'd go on but I've already talked about chess here a few times. If you're curious this link will get you started.

Pass the board to the piece you want a move list from.

You’re correct that the board data needs to be where the moves are. But the board is mutable so it’s a poor choice to make into an objects state. So just pass it as a parameter to a method.

Speaking of immutable, pieces don’t need to know where they are. Let the board keep track of that. All the pieces need to know is what their moves are and what their color is.

Let the board be a 2D array of references to such pieces and finding them will be a snap. Might seem weird until you introduce a null object piece that has blank as its color. Since it generates no moves you can generate your move list simply by looping the board and calling a line like this:

legalMoves.addAll( board[x][y].generateMoves(x, y, board, turn) ); 

Done this way your objects are immutable. All the stuff that changes gets passed in. Makes debugging a breeze and might even get optimized by the virtual machine.

If you're concerned with history you can use piece types to handle the stranger rules of chess. Kings become MovedKings when moved etc.

I'd go on but I've already talked about chess here a few times. If you're curious this link will get you started.

Pass the board to the piece you want a move list from.

You’re correct that the board data needs to be where the moves are. But the board is mutable so it’s a poor choice to make into an objects state. So just pass it as a parameter to a method.

Speaking of immutable, pieces don’t need to know where they are. Let the board keep track of that. All the pieces need to know is what their moves are and what their color is.

Let the board be a 2D array of references to such pieces and talking to them will be a snap. Might seem weird until you introduce a null object piece that has blank as its color. Since it generates no moves you can generate your move list simply by looping the board and calling a line like this:

legalMoves.addAll( board[x][y].generateMoves(x, y, board, turn) ); 

Done this way your objects are immutable. All the stuff that changes gets passed in. Makes debugging a breeze and might even get optimized by the virtual machine.

If you're concerned with history you can use piece types to handle the stranger rules of chess. Kings become MovedKings when moved etc.

I'd go on but I've already talked about chess here a few times. If you're curious this link will get you started.

added 1 character in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

Pass the board to the piece you want a move list from.

You’re correct that the board data needs to be where the moves are. But the board is mutable so it’s a poor choice to make into an objects state. So just pass it as a parameter to a method.

Speaking of beautifulimmutable, pieces don’t need to know where they are. Let the board keep track of that. All the pieces need to know is what their moves are and what their color is.

Let the board be a 2D Arrayarray of references to such pieces and finding them will be a snap. Might seem weird until you introduce a null object piece that has blank as its color. Since it generates no moves you can generate your move list simply by looping the board and calling a line like this:

legalMoves.addAll( board[x][y].generateMoves(x, y, board, turn) ); 

Done this way your objects are immutable. All the stuff that changes gets passed in. Makes debugging a breeze and might even get optimized by the virtual machine.

If you're concerned with history you can use piece types to handle the stranger rules of chess. Kings become MovedKings when moved etc.

I'd go on but I've already talked about chess here before a few times. If you're curious this link will get you started.

Pass the board to the piece you want a move list from.

You’re correct that the board data needs to be where the moves are. But the board is mutable so it’s a poor choice to make into an objects state. So just pass it as a parameter to a method.

Speaking of beautiful pieces don’t need to know where they are. Let the board keep track of that. All the pieces need to know is what their moves are and what their color is.

Let the board be a 2D Array of references to such pieces and finding them will be a snap. Might seem weird until you introduce a null object piece that has blank as its color. Since it generates no moves you can generate your move list simply by looping the board and calling a line like this:

legalMoves.addAll( board[x][y].generateMoves(x, y, board, turn) ); 

Done this way your objects are immutable. All the stuff that changes gets passed in. Makes debugging a breeze and might even get optimized by the virtual machine.

If you're concerned with history you can use piece types to handle the stranger rules of chess. Kings become MovedKings when moved etc.

I'd go on but I've talked about chess here before a few times. If you're curious this link will get you started.

Pass the board to the piece you want a move list from.

You’re correct that the board data needs to be where the moves are. But the board is mutable so it’s a poor choice to make into an objects state. So just pass it as a parameter to a method.

Speaking of immutable, pieces don’t need to know where they are. Let the board keep track of that. All the pieces need to know is what their moves are and what their color is.

Let the board be a 2D array of references to such pieces and finding them will be a snap. Might seem weird until you introduce a null object piece that has blank as its color. Since it generates no moves you can generate your move list simply by looping the board and calling a line like this:

legalMoves.addAll( board[x][y].generateMoves(x, y, board, turn) ); 

Done this way your objects are immutable. All the stuff that changes gets passed in. Makes debugging a breeze and might even get optimized by the virtual machine.

If you're concerned with history you can use piece types to handle the stranger rules of chess. Kings become MovedKings when moved etc.

I'd go on but I've already talked about chess here a few times. If you're curious this link will get you started.

added 191 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
added 191 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading