Skip to content
This repository has been archived by the owner on Dec 13, 2019. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ldct committed May 10, 2019
1 parent 6134a4e commit e72f164
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
9 changes: 3 additions & 6 deletions packages/tic-tac-toe-bot/src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Node, UninstallVirtualMessage } from "@counterfactual/node";
import { Address, Node as NodeTypes } from "@counterfactual/types";
import { ethers } from "ethers";
import { Zero } from "ethers/constants";
import { BigNumber, bigNumberify } from "ethers/utils";
import { v4 as generateUUID } from "uuid";
Expand Down Expand Up @@ -91,11 +90,9 @@ function respond(
nodeAddress: Address,
{ data: { appInstanceId, newState } }
) {
const { board, players, turnNum, winner } = newState;
const playerAddress = ethers.utils.HDNode.fromExtendedKey(
nodeAddress
).derivePath("0").address;
const botPlayerNumber = players.indexOf(playerAddress) + 1;
const { board, turnNum, winner } = newState;
// in test and prod, bot is always the second player
const botPlayerNumber = 2;
const isBotTurn =
bigNumberify(turnNum).toNumber() % 2 === botPlayerNumber - 1;
const noWinnerYet =
Expand Down
10 changes: 1 addition & 9 deletions packages/tic-tac-toe-bot/test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,6 @@ describe("ttt-bot", () => {
intermediaries: [playgroundNode.publicIdentifier],
proposedToIdentifier: nodeBot.publicIdentifier,
initialState: {
players: [
ethers.utils.HDNode.fromExtendedKey(
nodeAlice.publicIdentifier
).derivePath("0").address,
ethers.utils.HDNode.fromExtendedKey(
nodeBot.publicIdentifier
).derivePath("0").address
],
turnNum: 0,
winner: 0,
board: [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
Expand All @@ -178,7 +170,7 @@ describe("ttt-bot", () => {
actionEncoding:
"tuple(uint8 actionType, uint256 playX, uint256 playY, tuple(uint8 winClaimType, uint256 idx) winClaim)",
stateEncoding:
"tuple(address[2] players, uint256 turnNum, uint256 winner, uint256[3][3] board)"
"tuple(uint256 turnNum, uint256 winner, uint256[3][3] board)"
},
asset: {
assetType: 0
Expand Down

0 comments on commit e72f164

Please sign in to comment.