Skip to content

JulioJu/ArtificialIntelligenceConnectFourGame

Repository files navigation

Sommaire

Further documentation

See ./rapport_ecrit/rapport.md

Usage

  • To use it:

    1. Compile with the TypeScript compiler: ./node_modules/.bin/tsc
    2. Download require.js (see https://requirejs.org/docs/start.html) into ./app/requirejs/lib/
    3. Launch the app:
      • EITHER (for Browsersync)
        pushd  app && ../node_modules/.bin/browser-sync start --server --index ./index.html --files ./ & popd
        
        • browser-sync should be launch in app/ because app is our root folder.
        • Thanks BrowserSync, each modification saved automatically reload the app in the Browser :-).
        • We could also symply use yarn browsersync or npm browsersync.
      • OR firefox ./app/index.html (or click on the file)
  • In queryParam, key is case sensitive, value isn't case sensitive.

    • e.g:
      • connect-four-game.html?gamemode=multiplayer&first_gamer=red&ai_red=heuristic_column&ai_yellow=heuristic_column
      • gamemode is case sensitive, multiplayer isn't case sensitive.

Google Chrome issues with history

Note about es6 Modules in Browsers (deprecated)

THIS SECTION IS DEPRECATED , now the app use require.js and no longer es6 modules in compiled code.

  • This app use Modules. Therefore, we must have a recent Browser (e.g Firefox >= 60, and Firefox >= 61 to the support by the DevTools).

  • We can't launch the app with chromium ./app/index.html, otherwise we have error "Origin null is not allowed by Access-Control-Allow-Origin". We must use a server with chromium, like browser-sync.

  • With Firefox, we have not this error, that's why we could use command firefox ./app/index.html to launch the app. But, in this case, javascript files must be under the folder that contains index.html. If the javascript file is in a parent folder (e.g. in index.html : <script type="module" src="../index.js" />) we have the followings errors: * "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///home/julioju/DCISS/IA/ArtificialIntelligenceConnectFour/index.js. (Reason: CORS request not http)." with a link to https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSRequestNotHttp * and "Module source URI is not allowed in this document: “file:///home/julioju/DCISS/IA/ArtificialIntelligenceConnectFour/index.js”" * We could simply use Parcel to develop with module files https://github.com/parcel-bundler/parcel

  • We could also use scripts defined in ./package.json.

  • In Vim, with the plugin ALE, do not forget that linter lint only one files… Therefore, with Vim it's cool to run yarn compileAndLint for development.

  • To use under Chrome or for Firefox < 60 without server simply compile with tsc with options --outFile whatever.js and --module AMD. JQuery is compiled with AMD modules and require.js. Using a fat compiler chain with Gulp and WebPack isn't interesting.

  • In Firefox, when page is loaded, we must close then open again DevTools to see TypeScript files in the console and Debugger. See also: https://bugzilla.mozilla.org/show_bug.cgi?id=1443247

  • Tested also with: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Node_server_without_framework as for resolve AJAX errors with Chrome (https://developer.mozilla.org/en-US/docs/Learn/Server-side/Node_server_without_framework ). Without reslults.

Cool functionality

  • You could see that when you click several time very quickly with your mouse you add each time a new checker ! Contrary to before, checkers that are still animated when a new checker is added don't jump ! It's because each checker has it's own @keyframes.
    • Note that each checker start to move on the top of the screen !!! Even if you resize your Browser window !!! And this behaviour works for each row !!!!!

Notes on code developed

  • To retrieve url parm see:

  • Form in index.ts is not validated before it is submits. As code is client-side, and I only use radio buttons with a default check, I believe it's not useful to process validation. If the user want break the code with inspector or by change source code, it could ! ;-).

    • Otherwise in connect-four-game.ts it could be interesting to validate the URL.
  • In Firefox, when dev tools are open, the size of the window element is has a hight a little bit taller than the real hight of the screen.

  • In page connect-four-game.html, when we see headers Developpers tools, each time we click to add a checker, a new tag style is created that correspond to the checker added. In Firefox 52, style tags are not displayed with cool \n, little bit hard to read if all definitions are in the same tag. That's why I create a tag per checker added.

Manipulate CSS Object Model (CSSOM)

Animation (keyframes):

CSS colors / images

Conventions

* In javascript / typescript folders, files that have the same name that a html
    file are directly included to the html file
    e.g. in `./app/connect-four-game.html`:
    ```
    <script type="module" >
    import { main } from
    './javascript/connect-four-game/connect-four-game.js';
    main();
    </script>
    ```

Browser configuration

console.clear

  • Do not forget to use console.clear otherwise as we print objects very fat with a very long tree the browser crashes.

    • Same problem even if the Web Console isn't opened / displayed.
  • Do not forget to don't open too much softwares when you use this app. Memory available in the Browser (before crash) seems to depend of the global memory available in the computer (it's logical).

Firefox

  • Firefox 65 has its tab that stop to work. Warning is in the Console. Others tabs continue to work.
  • Activate Persitence log in Firefox 65 bypass completely console.clear instruction contrary to Chromium.

Chromium

  • Activate Preserve log in Chromium does not seems preserve all objects. It preserve only what is already printed.
  • On Chromium, without console.clear added, with have an error message that appears automatically with message Paused before potential out-of-memory crash
  • When calculs are fat, animations are not rendered perfectly in Chromium contrary to Firefox.

Timeout

Firefox

Chromium

  • ?????

performance.now accuracy

  • BIG WARNING: DUE TO SECURITY THREATS LIKE SPECTRE DO NOT FORGET TO RESET ANY MODIFICATIONS!!!!

Firefox

Chromium

  • ??????

TODO (not important for the teacher)

Credits

About

Scholar project of Artificial Intelligence on game Connect Four

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published