Skip to main content
edited tags
Link
Gypsy Spellweaver
  • 5.5k
  • 2
  • 18
  • 34
updates in _italics_
Source Link

I'm thinking about an assignment based around the game 2048. This would be towards the end of a firstfirst programming course at the university level and assumes the students have been introduced to at least two dimensional arrays, loops, conditionals and methods. The purpose is to have the students practice these skills.

I would represent the board as a two dimensional array of int.

I would require a method (e.g. merge(int[] row)) which does the work on an individual row of the puzzle when the move is to slide left. The idea is to encapsulate the work of a slide in a single, testable method. This also emphasizes that a two dimensional array is an array of array, and that one can work on a single row at a time.

What are your opinions on the following ideas:

  1. Should a single move in the game be implemented as (move(direction)) or as individual methods (up() down() left() right())?

  2. One idea for completing the game involves rotating the board by multiples of 90 degrees. Then a move can be implemented as a three step process:

    1. Rotate board to one orientation
    2. Slide all rows left (merge(board[row]) for each row
    3. Rotate board back to original orientation
  3. Another idea is to show them that move right can be implemented by the process

    1. reverse a row
    2. slide it left (merge(board[row])
    3. reverse the row again
    4. For columns, copy the values from a column into a one dimensional temp array, then perform the merge(temp) and then copy back to the board. This may also require reverses, depending on the up/down selection.
  4. Require a method to produce a list of empty cells for use in picking the location of the next "insertion". This could be a list of int to demonstrate how a single index can map to a row/col using div and mod operations. Alternatively, it could be a list of pairs of row/column.

  5. The last wrinkle is to decide what to actually stored in each board location. The simple answer is just the value. However, an interesting variation might be to store the log2 of the value. By doing this, you get an index that can be used to select, for example, the background color of each square of the board. This changes the logic of merge(), so that combining adjacent cells ups the value by 1, rather than adding two values together.

Am I trying to put too many different concepts into this assignment? Your opinions and suggestions are appreciated.

Thanks

I'm thinking about an assignment based around the game 2048. This would be towards the end of a first programming course and assumes the students have been introduced to at least two dimensional arrays, loops, conditionals and methods. The purpose is to have the students practice these skills.

I would represent the board as a two dimensional array of int.

I would require a method (e.g. merge(int[] row)) which does the work on an individual row of the puzzle when the move is to slide left. The idea is to encapsulate the work of a slide in a single, testable method.

What are your opinions on the following ideas:

  1. Should a single move in the game be implemented as (move(direction)) or as individual methods (up() down() left() right())?

  2. One idea for completing the game involves rotating the board by multiples of 90 degrees. Then a move can be implemented as a three step process:

    1. Rotate board to one orientation
    2. Slide all rows left (merge(board[row]) for each row
    3. Rotate board back to original orientation
  3. Another idea is to show them that move right can be implemented by the process

    1. reverse a row
    2. slide it left (merge(board[row])
    3. reverse the row again
    4. For columns, copy the values from a column into a one dimensional temp array, then perform the merge(temp) and then copy back to the board. This may also require reverses, depending on the up/down selection.
  4. Require a method to produce a list of empty cells for use in picking the location of the next "insertion". This could be a list of int to demonstrate how a single index can map to a row/col using div and mod operations. Alternatively, it could be a list of pairs of row/column.

  5. The last wrinkle is to decide what to actually stored in each board location. The simple answer is just the value. However, an interesting variation might be to store the log2 of the value. By doing this, you get an index that can be used to select, for example, the background color of each square of the board. This changes the logic of merge(), so that combining adjacent cells ups the value by 1, rather than adding two values together.

Am I trying to put too many different concepts into this assignment? Your opinions and suggestions are appreciated.

Thanks

I'm thinking about an assignment based around the game 2048. This would be towards the end of a first programming course at the university level and assumes the students have been introduced to at least two dimensional arrays, loops, conditionals and methods. The purpose is to have the students practice these skills.

I would represent the board as a two dimensional array of int.

I would require a method (e.g. merge(int[] row)) which does the work on an individual row of the puzzle when the move is to slide left. The idea is to encapsulate the work of a slide in a single, testable method. This also emphasizes that a two dimensional array is an array of array, and that one can work on a single row at a time.

What are your opinions on the following ideas:

  1. Should a single move in the game be implemented as (move(direction)) or as individual methods (up() down() left() right())?

  2. One idea for completing the game involves rotating the board by multiples of 90 degrees. Then a move can be implemented as a three step process:

    1. Rotate board to one orientation
    2. Slide all rows left (merge(board[row]) for each row
    3. Rotate board back to original orientation
  3. Another idea is to show them that move right can be implemented by the process

    1. reverse a row
    2. slide it left (merge(board[row])
    3. reverse the row again
    4. For columns, copy the values from a column into a one dimensional temp array, then perform the merge(temp) and then copy back to the board. This may also require reverses, depending on the up/down selection.
  4. Require a method to produce a list of empty cells for use in picking the location of the next "insertion". This could be a list of int to demonstrate how a single index can map to a row/col using div and mod operations. Alternatively, it could be a list of pairs of row/column.

  5. The last wrinkle is to decide what to actually stored in each board location. The simple answer is just the value. However, an interesting variation might be to store the log2 of the value. By doing this, you get an index that can be used to select, for example, the background color of each square of the board. This changes the logic of merge(), so that combining adjacent cells ups the value by 1, rather than adding two values together.

Am I trying to put too many different concepts into this assignment? Your opinions and suggestions are appreciated.

Thanks

Source Link

Project based on game 2048

I'm thinking about an assignment based around the game 2048. This would be towards the end of a first programming course and assumes the students have been introduced to at least two dimensional arrays, loops, conditionals and methods. The purpose is to have the students practice these skills.

I would represent the board as a two dimensional array of int.

I would require a method (e.g. merge(int[] row)) which does the work on an individual row of the puzzle when the move is to slide left. The idea is to encapsulate the work of a slide in a single, testable method.

What are your opinions on the following ideas:

  1. Should a single move in the game be implemented as (move(direction)) or as individual methods (up() down() left() right())?

  2. One idea for completing the game involves rotating the board by multiples of 90 degrees. Then a move can be implemented as a three step process:

    1. Rotate board to one orientation
    2. Slide all rows left (merge(board[row]) for each row
    3. Rotate board back to original orientation
  3. Another idea is to show them that move right can be implemented by the process

    1. reverse a row
    2. slide it left (merge(board[row])
    3. reverse the row again
    4. For columns, copy the values from a column into a one dimensional temp array, then perform the merge(temp) and then copy back to the board. This may also require reverses, depending on the up/down selection.
  4. Require a method to produce a list of empty cells for use in picking the location of the next "insertion". This could be a list of int to demonstrate how a single index can map to a row/col using div and mod operations. Alternatively, it could be a list of pairs of row/column.

  5. The last wrinkle is to decide what to actually stored in each board location. The simple answer is just the value. However, an interesting variation might be to store the log2 of the value. By doing this, you get an index that can be used to select, for example, the background color of each square of the board. This changes the logic of merge(), so that combining adjacent cells ups the value by 1, rather than adding two values together.

Am I trying to put too many different concepts into this assignment? Your opinions and suggestions are appreciated.

Thanks