
from game import DiscState

class TextualRuntime:

  def __init__(self, game):
    self.game = game
    self.state = {
      "continue": True
    }

  def start(self):
    while self.state["continue"]:
      self.render()
      self.eval(self.get_input())

  def render(self):
    str_repr = ["Current board state:\n"]
    str_repr += [" %i " % col_index for col_index in range(self.game.grid.width)]
    for row in self.game.grid:
      row_repr = []
      for disc_value in row:
        if disc_value is DiscState.empty:
          row_repr.append("| |")
        elif disc_value is DiscState.red:
          row_repr.append("|O|")
        else:  # disc_value is black
          row_repr.append("|X|")
      row_repr.append("\n")
      str_repr += row_repr
    print("".join(str_repr))

  def get_input(self):
    return input("--> ")

  def eval(self, command):
    tokens = command.split()
    if len(tokens) == 1:
      if tokens[0] == "quit":
        self.state["continue"] = False



from game import DiscState

class TextualRuntime:

  def __init__(self, game):
    self.game = game
    self.state = {
      "continue": True
    }

  def start(self):
    while self.state["continue"]:
      self.render()
      self.eval(self.get_input())

  def render(self):
    str_repr = ["Current board state:\n"]
    str_repr += [" %i " % col_index for col_index in range(self.game.grid.width)] + ["\n"]
    for row in self.game.grid:
      row_repr = []
      for disc_value in row:
        if disc_value is DiscState.empty:
          row_repr.append("| |")
        elif disc_value is DiscState.red:
          row_repr.append("|O|")
        else:  # disc_value is black
          row_repr.append("|X|")
      row_repr.append("\n")
      str_repr += row_repr
    print("".join(str_repr))

  def get_input(self):
    return input("--> ")

  def eval(self, command):
    tokens = command.split()
    if len(tokens) == 1:
      if tokens[0] == "quit":
        self.state["continue"] = False
      elif tokens[0].isdigit():
        col_index = int(tokens[0])
        new_point = self.game.try_turn(self.game.current_player, col_index)


Add ability to drop discs on slots
Add ability to drop discs on slots

  
  from game import DiscState
  
  class TextualRuntime:
  
    def __init__(self, game):
      self.game = game
      self.state = {
        "continue": True
      }
  
    def start(self):
      while self.state["continue"]:
        self.render()
        self.eval(self.get_input())
  
    def render(self):
      str_repr = ["Current board state:\n"]
-     str_repr += [" %i " % col_index for col_index in range(self.game.grid.width)]
+     str_repr += [" %i " % col_index for col_index in range(self.game.grid.width)] + ["\n"]
      for row in self.game.grid:
        row_repr = []
        for disc_value in row:
          if disc_value is DiscState.empty:
            row_repr.append("| |")
          elif disc_value is DiscState.red:
            row_repr.append("|O|")
          else:  # disc_value is black
            row_repr.append("|X|")
        row_repr.append("\n")
        str_repr += row_repr
      print("".join(str_repr))
  
    def get_input(self):
      return input("--> ")
  
    def eval(self, command):
      tokens = command.split()
      if len(tokens) == 1:
        if tokens[0] == "quit":
          self.state["continue"] = False
+       elif tokens[0].isdigit():
+         col_index = int(tokens[0])
+         new_point = self.game.try_turn(self.game.current_player, col_index)
  
  
Add ability to drop discs on slots
## Code Before:

from game import DiscState

class TextualRuntime:

  def __init__(self, game):
    self.game = game
    self.state = {
      "continue": True
    }

  def start(self):
    while self.state["continue"]:
      self.render()
      self.eval(self.get_input())

  def render(self):
    str_repr = ["Current board state:\n"]
    str_repr += [" %i " % col_index for col_index in range(self.game.grid.width)]
    for row in self.game.grid:
      row_repr = []
      for disc_value in row:
        if disc_value is DiscState.empty:
          row_repr.append("| |")
        elif disc_value is DiscState.red:
          row_repr.append("|O|")
        else:  # disc_value is black
          row_repr.append("|X|")
      row_repr.append("\n")
      str_repr += row_repr
    print("".join(str_repr))

  def get_input(self):
    return input("--> ")

  def eval(self, command):
    tokens = command.split()
    if len(tokens) == 1:
      if tokens[0] == "quit":
        self.state["continue"] = False


## Instruction:
Add ability to drop discs on slots
## Code After:

from game import DiscState

class TextualRuntime:

  def __init__(self, game):
    self.game = game
    self.state = {
      "continue": True
    }

  def start(self):
    while self.state["continue"]:
      self.render()
      self.eval(self.get_input())

  def render(self):
    str_repr = ["Current board state:\n"]
    str_repr += [" %i " % col_index for col_index in range(self.game.grid.width)] + ["\n"]
    for row in self.game.grid:
      row_repr = []
      for disc_value in row:
        if disc_value is DiscState.empty:
          row_repr.append("| |")
        elif disc_value is DiscState.red:
          row_repr.append("|O|")
        else:  # disc_value is black
          row_repr.append("|X|")
      row_repr.append("\n")
      str_repr += row_repr
    print("".join(str_repr))

  def get_input(self):
    return input("--> ")

  def eval(self, command):
    tokens = command.split()
    if len(tokens) == 1:
      if tokens[0] == "quit":
        self.state["continue"] = False
      elif tokens[0].isdigit():
        col_index = int(tokens[0])
        new_point = self.game.try_turn(self.game.current_player, col_index)

