Ruby OOP tic-tac-toe hash / conditional / itiration -


Trying to make a classic tic tac toe in ruby, but my game_results () < / Code> method

I realize that this is not really complete and requires some more functionality, but now im just filling my board with the input items from the user and filled the board and the winner Trying to output.

When I can see on my board that we have a winner, then I call for the code game_results () and it gives me the right winner, but whenever If there is a tie game, then I get an error

Anyone have any ideas or solutions for what I am doing wrong with the operators? BTW I know that this is all very wrong, but I'm starting a new one.

  #require "pry" class game attr_reader: turn def initialize @turn = 1 @board = {a1: "", a2: "A3: A3: b3: b1: B, B2: "B2:", B3: "", C1: "", C2: "", C3: ""} and #def start_game #x = game.new # X.player_symbol #x.player_turn # X.check_game # end def intro puts in "Temporary Tic Tac TOE .." Rabbit! \ N "display_board Ends Diff PlayerSymbol Puts" Player 1, Pick Your Marker. X or O? \ N "i = Gets.chomp .upcase I == "X" @ p1 = "X" @ p2 = "O" elsif i == "O" @ p1 = "O" @ p2 = "X" and "puts" is not such a legitimate player ! "End end def player_ turn if @turn == 1" Player 1 turn. "@Tarn = 2 Player_mov (@ P1) and" Player 2 turn ". @tarn = 1 Player_mov (@ P2) End and Def Displays the board grid using display_board # hash value. "1 2 3" puts "A # {@ board [: a1]} | # {@ Board [: A2]} | # {@bird [: A3]} "puts" --- + --- + - - "puts" b # {@ board [: b1]} | # {@ Board [: b2]} | # {@bord [: b3]} "puts" --- + --- --- --- "# # {@ board [: c1]} | # {@ board [: c2]} | # {@ Board [: C3]} "And Defe Players _mov (N) # Player raises Square to claim. # Player symbol displays hash displays "move to" x = gets.chomp.downcase.to_sym @ board [x] = "# {n}" # player x / o display_board end df instructions for game_results # winner , Loser, or tie game if ((@ Board [: A1] == @ P1) & amp; amp; (@ Board [: A2] == @ P1) & amp; amp; (@bird [: A3] == @ P1)) || ((@ Board [: b1] == @ P1) & amp; (@ Board [: B2] == @ P1) & amp; (@ Board [: B3] == @ P1)) || ((@ Board [: C1] == @ P1) & amp; (@ Board [: C2] == @ P1) & amp; (@ Board [: C3] == @ P1)) || ((@ Board [: A1] == @ P1) & amp; (@ Board [: B1] == @ P1) & amp; (@ Board [: C1] == @ P1)) || ((@ Board [: A2] == @ P1) & amp; (@ Board [: B2] == @ P1) & amp; (@ Board [: C2] == @ P1)) || ((@ Board [: A3] == @ P1) & amp; (@ Board [: B3] == @ P1) & amp; (@ Board [: C3] == @ P1)) || ((@ Board [: A1] == @ P1) & amp; (@ Board [: B2] == @ P1) & amp; (@ Board [: C3] == @ P1)) || ((@ Board [: A3] == @ P1) & amp; (@ Board [: B2] == @ P1) & amp; (@ Board [: C1] == @ P1)) "Player # {@ P1} is the winner!" Elsf ((@ Board [: A1] == @ P2) & amp; (@ Board [: A2] == @ P2 ) & Amp; amp; (@ Board [: A3] == @ P2)) || ((@ Board [: B1] == @ P2) & amp; (@ Board [: B2] == @ P2) & amp; (@ Board [: B3] == @ P2)) || (@ Board [: C1] == @ P2) & amp; amp; (@ Board [: C2] == @ P2) & amp; (@ Board [: C3] == @ P2)) || (@ Board [: A1] == @ P2) & amp; (@ Board [: B1] == @ P2) & amp; (@ Board [: B1] == @ P2)) || ((@ Board [: A2] == @ P2) & amp; (@ Board [: B2] == @ P2) & amp; (@ Board [: C2] == @ P2)) || ((@ Board [: A3] == @ P2) & amp; (@ Board [: B3] == @ P2) & amp; (@ Board [: C3] == @ P2)) || ((@ Board [: A1] == @ P2) & amp; (@ Board [: B2] == @ P2) & amp; (@ Board [: C3] == @ P2)) || ((@ Board [: A3] == @ P2) & amp; (@ Board [: B2] == @ P2) & amp; (@ Board [: C1] == @ P2)) "Player # {@ P2} is the winner!" Elsf ((@ Board [: A1] == ("X" || "O")) & amp; amp; (@ Board [: A 2] == ("X" || "O")) & amp; amp; (@ Board [: A3] == ("X" || "O")) & amp; amp; (@ Board [ : B1] == ("x" || "o")) & amp; amp; (@ board [: b2] == ("x" || "o")) & amp; amp; (@ Board [: B3] == ("x" || "o")) & amp; (@ board [: c1] == ("x" || "o")) & amp; amp; (@ Board [: c2] == ("x" || "o")) & amp; amp; (@ board [: c3] == ("x" || "o")) # Empty elements should be shown in the hash A now makes a winning pair of "tie game" and the end of the player is not finished ending  


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -