Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 41a1edabed | |||
| 511add50ef |
1
PongP5JS
57
games.html
@ -1,57 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Retro City</title>
|
|
||||||
<script src='sketch.js' type="text/javascript"></script>
|
|
||||||
<link href='style.css' rel='stylesheet'>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="wraper">
|
|
||||||
<!--Header/Nav-->
|
|
||||||
<div class="header">
|
|
||||||
<h1 id="logo">Retro City</h1>
|
|
||||||
<ul class="nav">
|
|
||||||
<li><a href="index.html">Home</a></li>
|
|
||||||
<li><a href="pong.html">Pong</a></li>
|
|
||||||
<li><a href="systems.html">Systems</a></li>
|
|
||||||
<li><a href="games.html"><strong>Games</strong></a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--Catagories: Located on right-->
|
|
||||||
<div class="catagories">
|
|
||||||
<h3 class="titles">catagories</h5>
|
|
||||||
<ul>
|
|
||||||
<li><a href="#bertie">Bertie</a></li>
|
|
||||||
<li><a href="#zelda">Zelda</a></li>
|
|
||||||
<li><a href="#sonic">Sonic</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--Content for site-->
|
|
||||||
<div class="content">
|
|
||||||
<h2 class="titles" id="bertie">Bertie</h2>
|
|
||||||
<div class="text">
|
|
||||||
<img src="media/bertie.png" alt="">
|
|
||||||
<p>Bertie the Brain is the earliest known computer game to have a video display. released August 25, 1950, Bertie was a tic-tac-toe game featuring an artificial intelligence opponent with an adjustable difficulty level, and was created to demonstrate the additron tube, a miniature vacuum tube that was made obsolete by the transistor before it could be used in any machine other than Bertie. Bertie no longer exists, as the only machine to ever exist was disassembled after two weeks of display.</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<h2 class="titles" id="zelda">Zelda</h2>
|
|
||||||
<div class="text">
|
|
||||||
<img src="media/loz.png" alt="">
|
|
||||||
<p>The Legend of Zelda is an action-adventure video game developed and published by Nintendo and designed by Shigeru Miyamoto and Takashi Tezuka. Set in the fantasy land of Hyrule, the plot centers on a boy named Link, the playable protagonist, who aims to collect the eight fragments of the Triforce of Wisdom in order to rescue Princess Zelda from the antagonist, Ganon. During the course of the game, the player sees Link from a top-down perspective and must navigate him through the overworld and several dungeons, defeating enemies and finding secrets along the way.</p>
|
|
||||||
</div>
|
|
||||||
<h2 class="titles" id="sonic">Sonic the Hedgehog</h2>
|
|
||||||
<div class="text">
|
|
||||||
<img src="media/sonic.jpg" alt="">
|
|
||||||
<p>Sonic the Hedgehog[b] is a platform game developed by Sonic Team and published by Sega for the Sega Genesis console. The game was first released in North America in June 1991, and in PAL regions and Japan the following month. The game features an anthropomorphic hedgehog named Sonic in a quest to defeat Doctor Robotnik, a scientist who has imprisoned animals in robots and stolen the magical Chaos Emeralds. Sonic the Hedgehog's gameplay involves collecting rings as a form of health and a simple control scheme, with jumping and attacking controlled by a single button.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!--Footer-->
|
|
||||||
<div class="footer">
|
|
||||||
<p>Created by: Brandon Behar, Erin Sims, Wade Kelly-Higgs</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
59
index.html
@ -1,59 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Retro City</title>
|
|
||||||
<script src='sketch.js' type="text/javascript"></script>
|
|
||||||
<link href='style.css' rel='stylesheet'>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="wraper">
|
|
||||||
<!--Header/Nav-->
|
|
||||||
<div class="header">
|
|
||||||
<h1 id="logo">Retro City</h1>
|
|
||||||
<ul class="nav">
|
|
||||||
<li><a href="./index.html"><strong>Home</strong></a></li>
|
|
||||||
<li><a href="./pong.html">Pong</a></li>
|
|
||||||
<li><a href="./systems.html">Systems</a></li>
|
|
||||||
<li><a href="./games.html">Games</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--Catagories: Located on right-->
|
|
||||||
<div class="catagories">
|
|
||||||
<h3 class="titles">catagories</h5>
|
|
||||||
<ul>
|
|
||||||
<li><a href="#welcome">Welcome</a></li>
|
|
||||||
<li><a href="#about">About Us</a></li>
|
|
||||||
<li><a href="#contact">Contact US</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--Content for site-->
|
|
||||||
<div class="content">
|
|
||||||
<h2 class="titles" id="welcome">Welcome</h2>
|
|
||||||
<div class="text" id="centered">
|
|
||||||
<p>Welcome to RetroCity we are happy to have you here.</p>
|
|
||||||
<p>Our site is a place for the all things retro to live. We are fairly new so we don't have much on display at the moment but in time we may put more up. We hope that you enjoy your time on our site and hope that you come again to check if anything else has been added.</p>
|
|
||||||
</div>
|
|
||||||
<h2 class="titles" id="about">About Us</h2>
|
|
||||||
<div class="text" id="centered">
|
|
||||||
<p>Our team consists of three people</p>
|
|
||||||
<p>Brandon Behar, Erin Sims, and Wade Kelly-Higgs</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<h2 class="titles" id="contact">Contact Us</h2>
|
|
||||||
<div class="text" id="centered">
|
|
||||||
<p>The best way to get in contact is through email, irc, or discord. </p>
|
|
||||||
<p>Discord: ###########</p>
|
|
||||||
<p>IRC: ###########</p>
|
|
||||||
<p>Email: ######@#####.###</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!--Footer-->
|
|
||||||
<div class="footer">
|
|
||||||
<p>Created by: Brandon Behar, Erin Sims, Wade Kelly-Higgs</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
BIN
media/bertie.png
|
Before Width: | Height: | Size: 260 KiB |
BIN
media/loz.png
|
Before Width: | Height: | Size: 118 KiB |
BIN
media/nes.jpg
|
Before Width: | Height: | Size: 7.2 KiB |
BIN
media/nes2.jpg
|
Before Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 1.4 MiB |
BIN
media/segag1.jpg
|
Before Width: | Height: | Size: 8.3 KiB |
BIN
media/segag2.jpg
|
Before Width: | Height: | Size: 11 KiB |
BIN
media/sonic.jpg
|
Before Width: | Height: | Size: 28 KiB |
22
pong.html
@ -1,22 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Retro City</title>
|
|
||||||
<script src='sketch.js' type="text/javascript"></script>
|
|
||||||
<link href='style.css' rel='stylesheet'>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="wraper">
|
|
||||||
<!--Header/Nav-->
|
|
||||||
<div class="header">
|
|
||||||
<h1 id="logo">Retro City</h1>
|
|
||||||
<ul class="nav">
|
|
||||||
<li><a href="index.html">Home</a></li>
|
|
||||||
<li><a href="pong.html"><strong>Pong</strong></a></li>
|
|
||||||
<li><a href="systems.html">Systems</a></li>
|
|
||||||
<li><a href="games.html">Games</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<iframe id="pong" height="100%" width="75%" src="PongP5JS/index.html" frameborder="0"></iframe>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
135
style.css
@ -1,135 +0,0 @@
|
|||||||
html, body{
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
height: 100%;
|
|
||||||
background-color:rgb(86, 105, 110);
|
|
||||||
font-family: sans;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Header Bar */
|
|
||||||
#logo{
|
|
||||||
float:left;
|
|
||||||
color: red;
|
|
||||||
margin: inherit;
|
|
||||||
margin-left: 1em;
|
|
||||||
margin-top: 5px;
|
|
||||||
text-shadow: 1px 1px white, -1px -1px white, -1px 1px white, 1px -1px white;
|
|
||||||
}
|
|
||||||
|
|
||||||
#title{
|
|
||||||
color: red;
|
|
||||||
text-shadow: 1px 1px white, -1px -1px white, -1px 1px white, 1px -1px white;
|
|
||||||
text-align: center;
|
|
||||||
margin: 0;
|
|
||||||
margin-top: 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav li{
|
|
||||||
display: inline;
|
|
||||||
margin: .3em;
|
|
||||||
}
|
|
||||||
.nav ul{
|
|
||||||
background-color: black;
|
|
||||||
}
|
|
||||||
.nav a{
|
|
||||||
color: white;
|
|
||||||
font-size: 30px;
|
|
||||||
border-bottom: dotted 2px white;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
.nav a:hover{
|
|
||||||
color: red;
|
|
||||||
|
|
||||||
}
|
|
||||||
.nav{
|
|
||||||
margin: 0;
|
|
||||||
background-color: black;
|
|
||||||
height: 50px;
|
|
||||||
text-align: right;
|
|
||||||
padding-right: 2em;
|
|
||||||
padding-top: 5px;
|
|
||||||
border-bottom: solid red 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Content */
|
|
||||||
.content{
|
|
||||||
margin: 1em;
|
|
||||||
background-color: white;
|
|
||||||
border: solid black;
|
|
||||||
margin-right: 14em;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Catagories */
|
|
||||||
.catagories{
|
|
||||||
float: right;
|
|
||||||
width: 12em;
|
|
||||||
height: 5em;
|
|
||||||
background-color: white;
|
|
||||||
margin: 1em;
|
|
||||||
border: solid black;
|
|
||||||
padding-bottom: 2em;
|
|
||||||
overflow: auto;
|
|
||||||
height: 70%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.catagories a{
|
|
||||||
text-decoration: none;
|
|
||||||
height: 95%;
|
|
||||||
color: black;
|
|
||||||
border-bottom: dashed black 1px;;
|
|
||||||
}
|
|
||||||
|
|
||||||
.catagories a:hover{
|
|
||||||
border-bottom: solid red 1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.catagories li{
|
|
||||||
margin-top: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.catagories ul{
|
|
||||||
list-style-type: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.titles{
|
|
||||||
color: red;
|
|
||||||
text-shadow: 1px 1px black, -1px -1px black, -1px 1px black, 1px -1px black;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.text{
|
|
||||||
margin: 1em;
|
|
||||||
padding: 1em;
|
|
||||||
background-color: black;
|
|
||||||
color: white;
|
|
||||||
overflow: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer{
|
|
||||||
background-color: black;
|
|
||||||
border-top: solid red;
|
|
||||||
color: grey;
|
|
||||||
font-size: 10px;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
.footer p,a{
|
|
||||||
margin: 0;
|
|
||||||
padding: 5px;
|
|
||||||
}
|
|
||||||
.wraper{
|
|
||||||
}
|
|
||||||
|
|
||||||
#pong{
|
|
||||||
height: 40em;
|
|
||||||
margin-left: 10%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#centered{
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
img{
|
|
||||||
height: 200px;
|
|
||||||
float: left;
|
|
||||||
margin-right: 1em;
|
|
||||||
}
|
|
||||||
58
systems.html
@ -1,58 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Retro City</title>
|
|
||||||
<script src='sketch.js' type="text/javascript"></script>
|
|
||||||
<link href='style.css' rel='stylesheet'>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="wraper">
|
|
||||||
<!--Header/Nav-->
|
|
||||||
<div class="header">
|
|
||||||
<h1 id="logo">Retro City</h1>
|
|
||||||
<ul class="nav">
|
|
||||||
<li><a href="index.html">Home</a></li>
|
|
||||||
<li><a href="pong.html">Pong</a></li>
|
|
||||||
<li><a href="systems.html"><strong>Systems</strong></a></li>
|
|
||||||
<li><a href="games.html">Games</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--Catagories: Located on right-->
|
|
||||||
<div class="catagories">
|
|
||||||
<h3 class="titles">catagories</h5>
|
|
||||||
<ul>
|
|
||||||
<li><a href="#Odyssey">Odyssey</a></li>
|
|
||||||
<li><a href="#NES">NES</a></li>
|
|
||||||
<li><a href="#sega">Genesis</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--Content for site-->
|
|
||||||
<div class="content">
|
|
||||||
<h2 class="titles" id="Odyssey">Magnavox Odyssey</h2>
|
|
||||||
<div class="text">
|
|
||||||
<img src="media/odyssey.png" alt="">
|
|
||||||
<p>The Magnavox Odyssey is the first commercial home video game console. It was developed by a small team led by Ralph H. Baer at Sanders Associates and released by Magnavox in the United States in September 1972 and overseas the following year. The Odyssey consists of a white, black, and brown box which connects to a television set and two rectangular controllers attached by wires. It is capable of displaying three square dots on the screen in monochrome black and white, with differing behavior for the dots depending on the game played, and with no sound capabilities. Players place plastic overlays on the screen to create visuals, and the one or two players for each game control their dots with the three knobs and one button on the controller in accordance with the rules given for the game. The Odyssey console came packaged with dice, paper money, and other board game paraphernalia to go along with the games, and a peripheral controller—the first video game light gun—was sold separately.</p>
|
|
||||||
</div>
|
|
||||||
<h2 class="titles" id="NES">Nintendo Entertainment System</h2>
|
|
||||||
<div class="text">
|
|
||||||
<img src="media/nes.jpg" alt="">
|
|
||||||
<img src="media/nes2.jpg" alt="">
|
|
||||||
<p>The Nintendo Entertainment System (commonly abbreviated as NES) is an 8-bit home video game console that was developed and manufactured by Nintendo. It was initially released in Japan as the Family Computer (Japanese: ファミリーコンピュータ Hepburn: Famirī Konpyūta) (also known by the portmanteau abbreviation Famicom (ファミコン Famikon) and abbreviated as FC) on July 15, 1983, and was later released in New York City in 1985, and throughout the U.S as well as in Europe during 1986 and 1987, and Australia in 1987. In South Korea, it was known as the Hyundai Comboy (현대 컴보이 Hyeondae Keomboi) and was distributed by SK Hynix which then was known as Hyundai Electronics. The best-selling gaming console of its time, the NES helped revitalize the US video game industry following the video game crash of 1983. With the NES, Nintendo introduced a now-standard business model of licensing third-party developers, authorizing them to produce and distribute titles for Nintendo's platform. It was succeeded by the Super Nintendo Entertainment System.</p>
|
|
||||||
</div>
|
|
||||||
<h2 class="titles" id="sega">Sega Genisis</h2>
|
|
||||||
<div class="text">
|
|
||||||
<img src="media/segag1.jpg" alt="">
|
|
||||||
<img src="media/segag2.jpg" alt="">
|
|
||||||
<p>The Sega Genesis, known as the Mega Drive in regions outside of North America, is a 16-bit home video game console developed and sold by Sega. The Genesis was Sega's third console and the successor to the Master System. Sega released the console as the Mega Drive in Japan in 1988, followed by North America as the Genesis in 1989. In 1990, the console was distributed as the Mega Drive by Virgin Mastertronic in Europe, Ozisoft in Australasia, and Tectoy in Brazil. In South Korea, the systems were distributed by Samsung as the Super Gam*Boy and later the Super Aladdin Boy.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!--Footer-->
|
|
||||||
<div class="footer">
|
|
||||||
<p>Created by: Brandon Behar, Erin Sims, Wade Kelly-Higgs</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
364
tic tac toe.ipynb
Normal file
@ -0,0 +1,364 @@
|
|||||||
|
# Tic Tac Toe
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def drawBoard(board):
|
||||||
|
|
||||||
|
# This function prints out the board that it was passed.
|
||||||
|
|
||||||
|
# "board" is a list of 10 strings representing the board (ignore index 0)
|
||||||
|
|
||||||
|
print(' | |')
|
||||||
|
|
||||||
|
print(' ' + board[7] + ' | ' + board[8] + ' | ' + board[9])
|
||||||
|
|
||||||
|
print(' | |')
|
||||||
|
|
||||||
|
print('-----------')
|
||||||
|
|
||||||
|
print(' | |')
|
||||||
|
|
||||||
|
print(' ' + board[4] + ' | ' + board[5] + ' | ' + board[6])
|
||||||
|
|
||||||
|
print(' | |')
|
||||||
|
|
||||||
|
print('-----------')
|
||||||
|
|
||||||
|
print(' | |')
|
||||||
|
|
||||||
|
print(' ' + board[1] + ' | ' + board[2] + ' | ' + board[3])
|
||||||
|
|
||||||
|
print(' | |')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def inputPlayerLetter():
|
||||||
|
|
||||||
|
# Lets the player type which letter they want to be.
|
||||||
|
|
||||||
|
# Returns a list with the player<65>s letter as the first item, and the computer's letter as the second.
|
||||||
|
|
||||||
|
letter = ''
|
||||||
|
|
||||||
|
while not (letter == 'X' or letter == 'O'):
|
||||||
|
|
||||||
|
print('Do you want to be X or O?')
|
||||||
|
|
||||||
|
letter = input().upper()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# the first element in the list is the player<65>s letter, the second is the computer's letter.
|
||||||
|
|
||||||
|
if letter == 'X':
|
||||||
|
|
||||||
|
return ['X', 'O']
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
return ['O', 'X']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def whoGoesFirst():
|
||||||
|
|
||||||
|
# Randomly choose the player who goes first.
|
||||||
|
|
||||||
|
if random.randint(0, 1) == 0:
|
||||||
|
|
||||||
|
return 'computer'
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
|
||||||
|
return 'player'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def playAgain():
|
||||||
|
|
||||||
|
# This function returns True if the player wants to play again, otherwise it returns False.
|
||||||
|
|
||||||
|
print('Do you want to play again? (yes or no)')
|
||||||
|
|
||||||
|
return input().lower().startswith('y')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def makeMove(board, letter, move):
|
||||||
|
|
||||||
|
board[move] = letter
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def isWinner(bo, le):
|
||||||
|
|
||||||
|
# Given a board and a player<65>s letter, this function returns True if that player has won.
|
||||||
|
|
||||||
|
# We use bo instead of board and le instead of letter so we don<6F>t have to type as much.
|
||||||
|
|
||||||
|
return ((bo[7] == le and bo[8] == le and bo[9] == le) or # across the top
|
||||||
|
|
||||||
|
(bo[4] == le and bo[5] == le and bo[6] == le) or # across the middle
|
||||||
|
|
||||||
|
(bo[1] == le and bo[2] == le and bo[3] == le) or # across the bottom
|
||||||
|
|
||||||
|
(bo[7] == le and bo[4] == le and bo[1] == le) or # down the left side
|
||||||
|
|
||||||
|
(bo[8] == le and bo[5] == le and bo[2] == le) or # down the middle
|
||||||
|
|
||||||
|
(bo[9] == le and bo[6] == le and bo[3] == le) or # down the right side
|
||||||
|
|
||||||
|
(bo[7] == le and bo[5] == le and bo[3] == le) or # diagonal
|
||||||
|
|
||||||
|
(bo[9] == le and bo[5] == le and bo[1] == le)) # diagonal
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getBoardCopy(board):
|
||||||
|
|
||||||
|
# Make a duplicate of the board list and return it the duplicate.
|
||||||
|
|
||||||
|
dupeBoard = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for i in board:
|
||||||
|
|
||||||
|
dupeBoard.append(i)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return dupeBoard
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def isSpaceFree(board, move):
|
||||||
|
|
||||||
|
# Return true if the passed move is free on the passed board.
|
||||||
|
|
||||||
|
return board[move] == ' '
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getPlayerMove(board):
|
||||||
|
|
||||||
|
# Let the player type in their move.
|
||||||
|
|
||||||
|
move = ' '
|
||||||
|
|
||||||
|
while move not in '1 2 3 4 5 6 7 8 9'.split() or not isSpaceFree(board, int(move)):
|
||||||
|
|
||||||
|
print('What is your next move? (1-9)')
|
||||||
|
|
||||||
|
move = input()
|
||||||
|
|
||||||
|
return int(move)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def chooseRandomMoveFromList(board, movesList):
|
||||||
|
|
||||||
|
# Returns a valid move from the passed list on the passed board.
|
||||||
|
|
||||||
|
# Returns None if there is no valid move.
|
||||||
|
|
||||||
|
possibleMoves = []
|
||||||
|
|
||||||
|
for i in movesList:
|
||||||
|
|
||||||
|
if isSpaceFree(board, i):
|
||||||
|
|
||||||
|
possibleMoves.append(i)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if len(possibleMoves) != 0:
|
||||||
|
|
||||||
|
return random.choice(possibleMoves)
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getComputerMove(board, computerLetter):
|
||||||
|
|
||||||
|
# Given a board and the computer's letter, determine where to move and return that move.
|
||||||
|
|
||||||
|
if computerLetter == 'X':
|
||||||
|
|
||||||
|
playerLetter = 'O'
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
playerLetter = 'X'
|
||||||
|
|
||||||
|
for i in range(1, 10):
|
||||||
|
|
||||||
|
copy = getBoardCopy(board)
|
||||||
|
|
||||||
|
if isSpaceFree(copy, i):
|
||||||
|
|
||||||
|
makeMove(copy, computerLetter, i)
|
||||||
|
|
||||||
|
if isWinner(copy, computerLetter):
|
||||||
|
|
||||||
|
return i
|
||||||
|
|
||||||
|
|
||||||
|
# Check if the player could win on their next move, and block them
|
||||||
|
for i in range(1, 10):
|
||||||
|
|
||||||
|
copy = getBoardCopy(board)
|
||||||
|
|
||||||
|
if isSpaceFree(copy, i):
|
||||||
|
|
||||||
|
makeMove(copy, playerLetter, i)
|
||||||
|
|
||||||
|
if isWinner(copy, playerLetter):
|
||||||
|
|
||||||
|
return i
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Try to take one of the corners, if they are free.
|
||||||
|
|
||||||
|
move = chooseRandomMoveFromList(board, [1, 3, 7, 9])
|
||||||
|
|
||||||
|
if move != None:
|
||||||
|
|
||||||
|
return move
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Try to take the center, if it is free.
|
||||||
|
|
||||||
|
if isSpaceFree(board, 5):
|
||||||
|
|
||||||
|
return 5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Move on one of the sides.
|
||||||
|
|
||||||
|
return chooseRandomMoveFromList(board, [2, 4, 6, 8])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def isBoardFull(board):
|
||||||
|
|
||||||
|
# Return True if every space on the board has been taken. Otherwise return False.
|
||||||
|
for i in range(1, 10):
|
||||||
|
|
||||||
|
if isSpaceFree(board, i):
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print('Welcome to Tic Tac Toe!')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
# Reset the board
|
||||||
|
|
||||||
|
theBoard = [' '] * 10
|
||||||
|
|
||||||
|
playerLetter, computerLetter = inputPlayerLetter()
|
||||||
|
|
||||||
|
turn = whoGoesFirst()
|
||||||
|
|
||||||
|
print('The ' + turn + ' will go first.')
|
||||||
|
|
||||||
|
gameIsPlaying = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
while gameIsPlaying:
|
||||||
|
|
||||||
|
if turn == 'player':
|
||||||
|
|
||||||
|
# Player<65>s turn.
|
||||||
|
|
||||||
|
drawBoard(theBoard)
|
||||||
|
|
||||||
|
move = getPlayerMove(theBoard)
|
||||||
|
|
||||||
|
makeMove(theBoard, playerLetter, move)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if isWinner(theBoard, playerLetter):
|
||||||
|
|
||||||
|
drawBoard(theBoard)
|
||||||
|
|
||||||
|
print('Hooray! You have won the game!')
|
||||||
|
|
||||||
|
gameIsPlaying = False
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
if isBoardFull(theBoard):
|
||||||
|
|
||||||
|
drawBoard(theBoard)
|
||||||
|
|
||||||
|
print('The game is a tie!')
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
turn = 'computer'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
# Computer<65>s turn.
|
||||||
|
|
||||||
|
move = getComputerMove(theBoard, computerLetter)
|
||||||
|
|
||||||
|
makeMove(theBoard, computerLetter, move)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if isWinner(theBoard, computerLetter):
|
||||||
|
|
||||||
|
drawBoard(theBoard)
|
||||||
|
|
||||||
|
print('The computer has beaten you! You lose.')
|
||||||
|
|
||||||
|
gameIsPlaying = False
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
if isBoardFull(theBoard):
|
||||||
|
|
||||||
|
drawBoard(theBoard)
|
||||||
|
|
||||||
|
print('The game is a tie!')
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
turn = 'player'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if not playAgain():
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||