11export { start } ;
22
33import { deepCopy } from "../node_modules/utilsac/utility.js" ;
4- import { randomDecide } from "../../source/randomDecide.js"
4+ import { randomDecide } from "../../source/randomDecide.js" ;
55import { createIntelligence , decide } from "../../source/qlearn.js" ;
6- import { draw , report } from "./draw.js" ;
6+ import { draw } from "./draw.js" ;
77import { initialState } from "./initialState.js" ;
88import { scheduleNext } from "../scheduleNext.js" ;
99
10-
10+ const framesASecond = 60 ;
1111const isValidPosition = ( w , max ) => {
1212 return w >= 0 && w <= max ;
1313} ;
@@ -43,19 +43,19 @@ const updateGame = (action, state, reward) => {
4343 state . score += reward ;
4444 }
4545 } ) ;
46- state . missiles = state . missiles . filter ( ( [ dangerX , dangerY ] ) => {
46+ state . missiles = state . missiles . filter ( ( [ , dangerY ] ) => {
4747 return isValidPosition ( dangerY , state . maxY ) ;
4848 } ) ;
4949 state . missiles . forEach ( missile => {
50- missile [ 1 ] -= 1
50+ missile [ 1 ] -= 1 ;
5151 } ) ;
5252
5353 // the enemy emits a missile every n frames
5454 if ( state . frame % 4 === 0 ) {
5555 state . missiles . push ( state . positionEnemy . slice ( ) ) ;
5656 }
5757 // move enemy from left to right periodically
58- if ( state . frame % 60 > 30 ) {
58+ if ( state . frame % framesASecond > ( framesASecond / 2 ) ) {
5959 actions . moveLeft ( state , state . positionEnemy ) ;
6060 } else {
6161 actions . moveRight ( state , state . positionEnemy ) ;
@@ -67,15 +67,15 @@ const start = (options) => {
6767 reduceStateAndAction,
6868 learn,
6969 useIntelligence = true ,
70- MAX_FRAMES = 20000 ,
70+ MAX_FRAMES = 2 * 10 ** 4 ,
7171 display = false ,
7272 reward = - 1 ,
7373 } = options ;
7474
7575 const state = deepCopy ( initialState ) ;
7676 const intelligence = createIntelligence ( ) ;
7777
78- return new Promise ( ( resolve , reject ) => {
78+ return new Promise ( ( resolve ) => {
7979 const step = ( ) => {
8080 const scoreBefore = state . score ;
8181 let stateActions ;
@@ -99,7 +99,7 @@ const start = (options) => {
9999 const scoreDifference = scoreAfter - scoreBefore ;
100100 learn ( intelligence , previousStateActions , stateActions , actionName , actionNames , scoreDifference ) ;
101101 }
102- state . frame ++ ;
102+ state . frame += 1 ;
103103 if ( state . frame < MAX_FRAMES ) {
104104 scheduleNext ( step ) ;
105105 } else {
0 commit comments