forked from CoderAcademyEdu/morning-challenges-term1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path28_connect_four.rb
65 lines (54 loc) · 1.84 KB
/
28_connect_four.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Connect 4
# Ref: https://en.wikipedia.org/wiki/Connect_Four
#
# Task
# The game consists of a grid (7 columns and 6 rows) and two players
# that take turns to drop a plastic disc into the top of any chosen column.
#
# The pieces fall straight down, occupying the next available space within the column.
#
# The objective of the game is to be the first to form a horizontal, vertical, or
# diagonal line of four of one's own discs.
#
# Your task is to create a Class called Connect4 that has a method called play,
# which takes one argument for the column where the player is going to place their disc.
#
# Rules
# If a player successfully has 4 discs horizontally, vertically or diagonally
# then you should return "Player n wins!” where n is the current player either 1 or 2.
#
# If a player attempts to place a disc in a column that is full then you should
# return ”Column full!” and the next move must be taken by the same player.
#
# If the game has been won by a player, any following moves should return ”Game has finished!”.
#
# Any other move should return ”Player n has a turn” where n is the current player either 1 or 2.
#
# Player 1 starts the game every time and alternates with player 2. Your class must
# keep track of who's turn it is.
#
# The columns are numbered 0-6 left to right.
class Connect4
def initialize
@board = default_state
end
def default_state
return [
["0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0"],
["0", "0", "0", "0", "0", "0", "0"],
[1,2,3,4,5,6,7]
]
#last array refers to the
end
def render
@board.each_with_index do | row, index |
end
end
def player1
end
def player2
end