Skip to content

Comments

Template for a JavaScript/TypeScript Connect 4 Bot#1

Merged
DavidBetteridge merged 12 commits intoYorkCodeDojo:masterfrom
kevbite:master
Oct 31, 2016
Merged

Template for a JavaScript/TypeScript Connect 4 Bot#1
DavidBetteridge merged 12 commits intoYorkCodeDojo:masterfrom
kevbite:master

Conversation

@kevbite
Copy link
Contributor

@kevbite kevbite commented Oct 29, 2016

Thought I'd create us a connect 4 bot template in TypeScript in case we ever run this event again... plus gave me an excuse to write some TypeScript.


case GameState.RedToPlay:
if (game.RedPlayerID === playerId) {
makeMove(game, playerId)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promises should be parameterised with types in TS. That being said since x isnt even used, probably just remove the value altogether.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed the typing of the argument comes from the function definition anyway, so ignore this :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only used at top in const game = x.body; but seems to pull the types though without doing a x : IResponse<IGame> magic eh?!

}

registerTeam(teamName: string, password: string): Promise<IResponse<string>> {
const qs = querystring.stringify({ teamName: teamName, password: password });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

querystring.stringify({ teamName, password })

}

makeMove(playerId: string, password: string, columnNumber: number): Promise<IResponse<void>> {
const qs = querystring.stringify({ playerID: playerId, columnNumber: columnNumber, password: password });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

return new Promise((resolve, reject) => {
let req = http.request(options, (res) => {
if (res.statusCode < 200 || res.statusCode >= 300) {
return resolve({ ok: false, statusCode: res.statusCode, body: null });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eeeeeew. Why not just reject the promise? Resolving with OK makes me sad.

@@ -0,0 +1,3 @@
import * as assert from 'assert'

// I should of really written some test... :-/ No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should have* ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Knew you'd find a spelling mistake!

@DavidBetteridge DavidBetteridge merged commit 29cc80f into YorkCodeDojo:master Oct 31, 2016
jaymoid pushed a commit to jaymoid/Connect4 that referenced this pull request Dec 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants