Cloneable

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

Class Connect6State

  • Cloneable
    Connect6State - A representation of a Connect6  game state. We assume a square grid board size specified to be a positive integer less than or equal to 26. Size 19 is common. The first and second players place pieces on the board that are black and white, respectively. Each piece is placed in an unoccupied grid position. On the first turn, the first player places one piece. Afterwards, players alternate placing two pieces per turn. Play continues until either one player completes a consecutive line of 6 or more of their pieces or no play is possible. The player with 6 or more pieces in a horizontal, vertical, or diagonal line is the winner. If no legal play is possible, the game is a draw
  • Field Detail

    • BLACK

      public static final int BLACK
      a constant indicating a black player/piece
      See Also:Constant Field Values
    • WHITE

      public static final int WHITE
      a constant indicating a white player/piece
      See Also:Constant Field Values
    • NONE

      public static final int NONE
      a constant indicating no player/piece
      See Also:Constant Field Values
  • Constructor Detail

    • Connect6State

      public Connect6State​(int size)
      Creates Connect6State instance with an empty size-by-size grid and black to play.
      Parameters:size - game grid size
  • Method Detail

    • getPiece

      public int getPiece​(int row, int column)
      Given the row and column, returns the piece (BLACK, WHITE, or NONE) at that grid position.
      Parameters:row - - grid position rowcolumn - - grid position columnReturns:the piece (BLACK, WHITE, or NONE) at position (row, column)
    • getPlayer

      public int getPlayer()
      Returns the current player (BLACK or WHITE).
      Returns:the current player (BLACK or WHITE)
    • getSize

      public int getSize()
      Returns the grid size.
      Returns:the grid size
    • getWinner

      public int getWinner()
      Returns BLACK, WHITE, or NONE, if black has won, white has won, or no player has won, respectively. A player wins by placing 6 pieces consecutively in a line horizontally, vertically, or diagonally.
      Returns:the winner BLACK, WHITE, or NONE (if there is no winner)
    • playPiece

      public boolean playPiece​(int row, int column)
      The current player tries to play a piece at the given position. If the move is illegal (e.g. out of bounds, already occupied), false is returned. Otherwise, the current player's piece is placed at the given row and column, the current player changes or doesn't change according to the game rules, and true is returned. The current player changes after the first play, and after every two plays of a player thereafter.
      Parameters:row - attempted play rowcolumn - attempted play columnReturns:whether or not the attempted play was legal
    • toString

      public java.lang.String toString()
      Returns a String representation of the board. A '.' denotes an empty grid position. A '*' denotes a black piece. A 'o' denotes a white piece. Each grid row begins with a 1-based row number from 1 to size, right-justified within a width of 2 characters and followed by space-separated pieces of that row. Rows are printed in decreasing order, so that printed row 1 (internal grid row 0) is printed last. Under the board and aligned with each column, print successive lowercase letters 'a', 'b', 'c', ... until each column (of 26 columns max) is labeled with a letter. Thus, internal grid column number c is labeled by character (char) ('a' + c).
      Overrides:toString in class java.lang.Object
    • isGameOver

      public boolean isGameOver()
      Return whether or not the game is over.
      Returns:whether or not the game is over
    • clone

      public java.lang.Object clone()
      Returns a deep copy of this Connect6State object. This should be a deep clone. Changes to the copy should not alter the original, and vice versa.
      Overrides:clone in class java.lang.ObjectReturns:a deep copy of this Connect6State object
       
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education