Skip to content

Commit

Permalink
Add 'function evaluation' task (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastel authored and Uladzimir Halushka committed Nov 27, 2018
1 parent 9d0ab1d commit a3a4d46
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 21 deletions.
2 changes: 1 addition & 1 deletion client/src/components/racecourse/_racecourse.styl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

.race
display inline-block
width 25%
width 20%
box-sizing border-box
vertical-align top

Expand Down
3 changes: 2 additions & 1 deletion client/src/components/racecourse/names_and_icons.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export const names = [];

names[0] = 'START';
names[3] = 'FINISH';
names[4] = 'FINISH';

export const icons = [
'directions_walk',
'directions_run',
'directions_run',
'directions_run',
'sentiment_very_satisfied'
];
4 changes: 2 additions & 2 deletions client/src/consts/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export default {
TIMER_ICONS_SIZE: 30,
TASKS_LENGTH: 4,
TASKS_LENGTH: 5,
WINNERS: 5,
LAST_RACE: 3,
LAST_RACE: 4,
ANIMATION_DURATION: 500,
ANIMATION_NAME: 'move',
darkNight: '#1F2739',
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"version": "0.0.1",
"description": "",
"main": "index.js",
"engines": {
"node": "6.9.1"
},
"scripts": {
"build": "cross-env NODE_ENV=development webpack --config webpack.config.js",
"build:prod": "cross-env NODE_ENV=production webpack --config webpack.config.js",
Expand Down
31 changes: 31 additions & 0 deletions server/game/tasks/function_evaluation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const TASK_NAME = 'function_evaluation';

const MAX = 255;
const MIN = 1;

function getRandomInt() {
return Math.floor(Math.random() * (MAX - MIN) + MIN);
}

function createTaskFunction () {
return `(function function_evaluation() { return ${getRandomInt()} + ${getRandomInt()}; })`;
}

function solve({ fn }, answer) {
return eval(fn)() === answer;
}

function start() {
return {
name: TASK_NAME,
task: {
fn: createTaskFunction(),
},
};
}

export default {
name: TASK_NAME,
solve,
start,
};
4 changes: 3 additions & 1 deletion server/game/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ import {

import arithmetic from 'server/game/tasks/arithmetic';
import bin_arithmetic from 'server/game/tasks/binary_arithmetic';
import function_evaluation from 'server/game/tasks/function_evaluation';

import {
wrongTaskName
} from 'server/web_socket/message_creators';

const tasks = [arithmetic, bin_arithmetic];
const tasks = [arithmetic, function_evaluation, bin_arithmetic];

export function getFirstTask() {
if (tasks) {
return tasks[0] || ProtocolMessages.WIN;
}

return ProtocolMessages.WIN;
}

Expand Down
5 changes: 3 additions & 2 deletions server/validators/message_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import ProtocolMessages from 'server/constants/protocol_messages';

import arithmetic from 'server/game/tasks/arithmetic';
import bin_arithmetic from 'server/game/tasks/binary_arithmetic';

import function_evaluation from 'server/game/tasks/function_evaluation';
//todo: refactor
const name = arithmetic.name;
const bin_name = bin_arithmetic.name;
const fun_name = function_evaluation.name;

export function isGameCommand(message) {
const keys = Object.keys(ProtocolMessages);

for(let i = 0; i < keys.length; i++) {
if (ProtocolMessages[keys[i]] === message || name === message || bin_name === message) {
if (ProtocolMessages[keys[i]] === message || name === message || bin_name === message || fun_name === message) {
return true;
}
}
Expand Down
88 changes: 77 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ ajv@^4.7.0, ajv@^4.9.1:
co "^4.6.0"
json-stable-stringify "^1.0.1"

ajv@^5.0.0:
version "5.5.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965"
dependencies:
co "^4.6.0"
fast-deep-equal "^1.0.0"
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.3.0"

align-text@^0.1.1, align-text@^0.1.3:
version "0.1.4"
resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117"
Expand Down Expand Up @@ -1176,6 +1185,10 @@ character-parser@^2.1.1:
dependencies:
is-regex "^1.0.3"

charenc@~0.0.1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"

charm@~0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/charm/-/charm-0.1.2.tgz#06c21eed1a1b06aeb67553cdc53e23274bac2296"
Expand Down Expand Up @@ -1487,6 +1500,10 @@ cross-spawn@^3.0.1:
lru-cache "^4.0.1"
which "^1.2.9"

crypt@~0.0.1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"

cryptiles@2.x.x:
version "2.0.5"
resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-2.0.5.tgz#3bdfecdc608147c1c67202fa291e7dca59eaa3b8"
Expand Down Expand Up @@ -2176,6 +2193,14 @@ extsprintf@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.0.2.tgz#e1080e0658e300b06294990cc70e1502235fd550"

fast-deep-equal@^1.0.0:
version "1.1.0"
resolved "http://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz#c053477817c86b51daa853c81e059b733d023614"

fast-json-stable-stringify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"

fast-levenshtein@~2.0.4:
version "2.0.6"
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
Expand Down Expand Up @@ -2766,6 +2791,10 @@ is-buffer@^1.1.5:
version "1.1.5"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc"

is-buffer@~1.1.1:
version "1.1.6"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"

is-builtin-module@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-1.0.0.tgz#540572d34f7ac3119f8f76c30cbc1b1e037affbe"
Expand Down Expand Up @@ -3008,6 +3037,10 @@ json-loader@^0.5.4:
version "0.5.4"
resolved "https://registry.yarnpkg.com/json-loader/-/json-loader-0.5.4.tgz#8baa1365a632f58a3c46d20175fc6002c96e37de"

json-schema-traverse@^0.3.0:
version "0.3.1"
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz#349a6d44c53a51de89b40805c5d5e59b417d3340"

json-schema@0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
Expand Down Expand Up @@ -3390,6 +3423,14 @@ math-expression-evaluator@^1.2.14:
version "1.2.17"
resolved "https://registry.yarnpkg.com/math-expression-evaluator/-/math-expression-evaluator-1.2.17.tgz#de819fdbcd84dccd8fae59c6aeb79615b9d266ac"

md5@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/md5/-/md5-2.2.1.tgz#53ab38d5fe3c8891ba465329ea23fac0540126f9"
dependencies:
charenc "~0.0.1"
crypt "~0.0.1"
is-buffer "~1.1.1"

media-typer@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
Expand Down Expand Up @@ -3448,9 +3489,9 @@ mime@1.3.4:
version "1.3.4"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.4.tgz#115f9e3b6b3daf2959983cb38f149a2d40eb5d53"

mime@1.3.x:
version "1.3.6"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.3.6.tgz#591d84d3653a6b0b4a3b9df8de5aa8108e72e5e0"
mime@^1.4.1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"

minimalistic-assert@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -4527,10 +4568,6 @@ querystring@0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"

ramda@^0.25.0:
version "0.25.0"
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.25.0.tgz#8fdf68231cffa90bc2f9460390a0cb74a29b29a9"

randomatic@^1.1.3:
version "1.1.7"
resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-1.1.7.tgz#c7abe9cc8b87c0baa876b19fde83fd464797e38c"
Expand All @@ -4548,6 +4585,16 @@ range-parser@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e"

raven@^2.2.1:
version "2.6.4"
resolved "https://registry.yarnpkg.com/raven/-/raven-2.6.4.tgz#458d4a380c8fbb59e0150c655625aaf60c167ea3"
dependencies:
cookie "0.3.1"
md5 "^2.2.1"
stack-trace "0.0.10"
timed-out "4.0.1"
uuid "3.3.2"

rc@^1.0.1, rc@^1.1.7:
version "1.2.1"
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.1.tgz#2e03e8e42ee450b8cb3dce65be1bf8974e1dfd95"
Expand Down Expand Up @@ -5022,6 +5069,12 @@ sax@~1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.2.tgz#fd8631a23bc7826bef5d871bdb87378c95647828"

schema-utils@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.3.0.tgz#f5877222ce3e931edae039f17eb3716e7137f8cf"
dependencies:
ajv "^5.0.0"

secure-keys@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/secure-keys/-/secure-keys-1.0.0.tgz#f0c82d98a3b139a8776a8808050b824431087fca"
Expand Down Expand Up @@ -5221,6 +5274,10 @@ sshpk@^1.7.0:
jsbn "~0.1.0"
tweetnacl "~0.14.0"

stack-trace@0.0.10:
version "0.0.10"
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"

"statuses@>= 1.3.1 < 2", statuses@~1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"
Expand Down Expand Up @@ -5420,6 +5477,10 @@ through@2, through@^2.3.6, through@~2.3, through@~2.3.1:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"

timed-out@4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f"

timed-out@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-2.0.0.tgz#f38b0ae81d3747d628001f41dafc652ace671c0a"
Expand Down Expand Up @@ -5567,12 +5628,13 @@ upper-case@^1.1.1:
version "1.1.3"
resolved "https://registry.yarnpkg.com/upper-case/-/upper-case-1.1.3.tgz#f6b4501c2ec4cdd26ba78be7222961de77621598"

url-loader@^0.5.7:
version "0.5.9"
resolved "https://registry.yarnpkg.com/url-loader/-/url-loader-0.5.9.tgz#cc8fea82c7b906e7777019250869e569e995c295"
url-loader@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/url-loader/-/url-loader-0.6.2.tgz#a007a7109620e9d988d14bce677a1decb9a993f7"
dependencies:
loader-utils "^1.0.2"
mime "1.3.x"
mime "^1.4.1"
schema-utils "^0.3.0"

url@^0.11.0:
version "0.11.0"
Expand Down Expand Up @@ -5609,6 +5671,10 @@ utils-merge@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.0.tgz#0294fb922bb9375153541c4f7096231f287c8af8"

uuid@3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"

uuid@^2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"
Expand Down

0 comments on commit a3a4d46

Please sign in to comment.