Set prettier config and pretti-fy everything

This commit is contained in:
2019-03-02 21:07:25 +02:00
parent 3264a86be7
commit 38af6495d0
18 changed files with 124 additions and 117 deletions

13
.prettierignore Normal file
View File

@@ -0,0 +1,13 @@
.nuxt/**
assets/**
dist/**
node_modules/**
plugins/ga.js
static/**
submodules/**
.prettierignore
.git*
Makefile
yarn.lock

3
.prettierrc.json Normal file
View File

@@ -0,0 +1,3 @@
{
"printWidth": 120
}

View File

@@ -3,6 +3,6 @@
"**/.nuxt/": true,
"**/dist/": true,
"**/node_modules/": true,
"submodules/": true,
"submodules/": true
}
}

View File

@@ -1,4 +1,3 @@
gardev.com
==========
# gardev.com
The page sitting at [gar.dev](https://gar.dev) and [gardev.com](https://gardev.com)

View File

@@ -7,8 +7,10 @@ Dark Orange: #B26009
Light Gray: #f5f5f5
*/
html, body {
margin: 0; padding: 0;
html,
body {
margin: 0;
padding: 0;
font-family: "Verdana", sans-serif;
font-size: 100%;
@@ -27,7 +29,7 @@ h1 {
margin-top: 3em;
margin-bottom: 0;
font-size: 2em;
color: #0085B2;
color: #0085b2;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.75);
}
@@ -45,10 +47,7 @@ input[type="button"] {
outline: 0 !important;
}
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
@media only screen and (min-device-width: 320px) and (max-device-width: 480px) {
main {
width: 320px;
}

View File

@@ -9,9 +9,9 @@
</template>
<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
import Cell from './Cell/Cell.vue';
import { CellState } from '~/plugins/tic-tac-toe/cell-state';
import { Component, Vue, Prop } from "vue-property-decorator";
import Cell from "./Cell/Cell.vue";
import { CellState } from "~/plugins/tic-tac-toe/cell-state";
@Component({ components: { Cell } })
export default class Board extends Vue {

View File

@@ -3,8 +3,8 @@
</template>
<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator'
import { CellState } from '~/plugins/tic-tac-toe/cell-state';
import { Component, Vue, Prop } from "vue-property-decorator";
import { CellState } from "~/plugins/tic-tac-toe/cell-state";
@Component
export default class Cell extends Vue {
@@ -17,14 +17,13 @@ export default class Cell extends Vue {
get classNames() {
return {
placed: this.state !== null,
x: this.state === 'x',
o: this.state === 'o'
}
x: this.state === "x",
o: this.state === "o"
};
}
}
</script>
<style lang="scss">
.cell {
width: 70px;
@@ -37,11 +36,11 @@ export default class Cell extends Vue {
&:not(.placed):not(:disabled):hover {
cursor: pointer;
background: #0085B2;
background: #0085b2;
}
&:not(.placed):not(:disabled):active {
box-shadow: inset 0px 0px 83px 0px rgba(0,0,0,0.38);
box-shadow: inset 0px 0px 83px 0px rgba(0, 0, 0, 0.38);
}
&.placed {

View File

@@ -28,29 +28,29 @@
</template>
<script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator';
import Board from './Board/Board.vue';
import Game from '~/plugins/tic-tac-toe/game';
import { AI } from '~/plugins/tic-tac-toe/ai';
import Player from '~/plugins/tic-tac-toe/player';
import { CellState } from '~/plugins/tic-tac-toe/cell-state';
import { Component, Vue, Watch } from "vue-property-decorator";
import Board from "./Board/Board.vue";
import Game from "~/plugins/tic-tac-toe/game";
import { AI } from "~/plugins/tic-tac-toe/ai";
import Player from "~/plugins/tic-tac-toe/player";
import { CellState } from "~/plugins/tic-tac-toe/cell-state";
@Component({ components: { Board }})
@Component({ components: { Board } })
export default class TicTacToe extends Vue {
wins: number = 0;
draws: number = 0;
losses: number = 0;
lastResultString: string = '';
lastResultString: string = "";
cellStates: CellState[] = [];
finished: boolean = false;
difficulty: AI.Difficulty = 'normal';
difficulty: AI.Difficulty = "normal";
private game: Game;
private ai: AI;
@Watch('difficulty', { immediate: true })
@Watch("difficulty", { immediate: true })
onDifficultyChange(newDifficulty: AI.Difficulty) {
if (this.ai) {
this.ai.difficulty = newDifficulty;
@@ -66,7 +66,7 @@ export default class TicTacToe extends Vue {
this.ai = new AI(this.game, this.difficulty);
this.cellStates = this.game.copyBoard();
this.finished = false;
this.lastResultString = '';
this.lastResultString = "";
}
place(index: number) {
@@ -91,17 +91,17 @@ export default class TicTacToe extends Vue {
private finishGame() {
this.finished = true;
switch(this.game.winner) {
switch (this.game.winner) {
case Player.HUMAN:
this.wins++;
this.lastResultString = 'You win! Congratulations!';
this.lastResultString = "You win! Congratulations!";
break;
case Player.AI:
this.lastResultString = 'The AI won. Better luck next time!';
this.lastResultString = "The AI won. Better luck next time!";
this.losses++;
break;
default:
this.lastResultString = 'It\'s a draw. Have another try!';
this.lastResultString = "It's a draw. Have another try!";
this.draws++;
}
}
@@ -109,25 +109,24 @@ export default class TicTacToe extends Vue {
</script>
<style lang="scss">
.new-game {
cursor: pointer;
padding: 10px 20px;
margin-top: 10px;
background: #fff;
color: #0085B2;
color: #0085b2;
text-decoration: none;
border: 1px solid #0085B2;
border: 1px solid #0085b2;
border-radius: 4px;
&:hover {
background: #0085B2;
background: #0085b2;
color: #fff;
}
&:active {
box-shadow: inset 0px 0px 83px 0px rgba(0,0,0,0.38);
box-shadow: inset 0px 0px 83px 0px rgba(0, 0, 0, 0.38);
}
}
@@ -144,7 +143,7 @@ export default class TicTacToe extends Vue {
text-align: center;
font-size: 0.8em;
cursor: pointer;
background: #0085B2;
background: #0085b2;
color: #fff;
border-bottom: 1px solid #00678a;
border-top: 1px solid #00678a;
@@ -167,7 +166,7 @@ export default class TicTacToe extends Vue {
}
&:active {
box-shadow: inset 0px 0px 83px 0px rgba(0,0,0,0.38);
box-shadow: inset 0px 0px 83px 0px rgba(0, 0, 0, 0.38);
}
input {
@@ -177,11 +176,11 @@ export default class TicTacToe extends Vue {
> .selected {
cursor: default;
background: #FF8F19;
border-color: #B26009 !important;
background: #ff8f19;
border-color: #b26009 !important;
&:hover {
background: #FF8F19;
background: #ff8f19;
}
&:active {
@@ -199,9 +198,9 @@ export default class TicTacToe extends Vue {
> h2 {
display: inline-block;
width: 200px;
color: #0085B2;
color: #0085b2;
font-weight: normal;
border-bottom: 1px solid #0085B2;
border-bottom: 1px solid #0085b2;
}
table {
@@ -224,11 +223,11 @@ export default class TicTacToe extends Vue {
border-radius: 2px;
&.wins {
background: #0085B2;
background: #0085b2;
}
&.losses {
background: #FF8F19;
background: #ff8f19;
}
&.draws {
@@ -237,9 +236,7 @@ export default class TicTacToe extends Vue {
}
}
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
@media only screen and (min-device-width: 320px) and (max-device-width: 480px) {
.stats {
position: static;
text-align: center;

View File

@@ -1,40 +1,40 @@
export default {
head: {
htmlAttrs: {
lang: 'en'
lang: "en"
},
title: 'Georgi Gardev',
title: "Georgi Gardev",
meta: [
{ charset: 'utf-8' },
{ name: 'author', content: 'Georgi Gardev' },
{ name: 'owner', content: 'Georgi Gardev' },
{ name: 'description', content: 'Personal Homepage of Georgi Gardev' },
{ name: 'copyright', content: 'Georgi Gardev 2014' },
{ name: 'robots', content: 'index, follow' },
{ name: 'revisit-after', content: '2 days' },
{ name: 'GOOGLEBOT', content: 'index, follow, all' },
{ name: 'audience', content: 'all' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' }
{ charset: "utf-8" },
{ name: "author", content: "Georgi Gardev" },
{ name: "owner", content: "Georgi Gardev" },
{ name: "description", content: "Personal Homepage of Georgi Gardev" },
{ name: "copyright", content: "Georgi Gardev 2014" },
{ name: "robots", content: "index, follow" },
{ name: "revisit-after", content: "2 days" },
{ name: "GOOGLEBOT", content: "index, follow, all" },
{ name: "audience", content: "all" },
{ name: "viewport", content: "width=device-width, initial-scale=1" }
]
},
css: [{ lang: 'scss', src: '@/assets/styles/main.scss' }],
css: [{ lang: "scss", src: "@/assets/styles/main.scss" }],
modules: [
[
'nuxt-fontawesome',
"nuxt-fontawesome",
{
component: 'fa',
component: "fa",
imports: [
{
set: '@fortawesome/free-solid-svg-icons',
icons: ['fas']
set: "@fortawesome/free-solid-svg-icons",
icons: ["fas"]
},
{
set: '@fortawesome/free-brands-svg-icons',
icons: ['fab']
set: "@fortawesome/free-brands-svg-icons",
icons: ["fab"]
}
]
}
]
],
plugins: [{ src: '~/plugins/ga.js', ssr: false }]
plugins: [{ src: "~/plugins/ga.js", ssr: false }]
};

View File

@@ -27,6 +27,8 @@
"dev": "nuxt-ts",
"build": "nuxt-ts build",
"start": "nuxt-ts start",
"generate": "nuxt-ts generate"
"generate": "nuxt-ts generate",
"lint": "prettier -c '**/*'",
"format": "prettier --write '**/*'"
}
}

View File

@@ -25,8 +25,8 @@
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import TicTacToe from '~/components/TicTacToe/TicTacToe.vue';
import { Component, Vue } from "vue-property-decorator";
import TicTacToe from "~/components/TicTacToe/TicTacToe.vue";
@Component({ components: { TicTacToe } })
export default class Home extends Vue {}
@@ -40,7 +40,7 @@ export default class Home extends Vue {}
border-radius: 5px;
&:hover {
color: #0085B2;
color: #0085b2;
}
&:active {

View File

@@ -1,9 +1,9 @@
import Game from './game';
import Game from "./game";
export class AI {
private static readonly INFINITY = 9;
constructor(private game: Game, public difficulty: AI.Difficulty = 'normal') {}
constructor(private game: Game, public difficulty: AI.Difficulty = "normal") {}
move() {
const move = this.chooseMove();
@@ -12,15 +12,15 @@ export class AI {
private chooseMove(): number[] {
switch (this.difficulty) {
case 'easy':
case "easy":
return this.randomChoice(this.game);
case 'normal':
case "normal":
if (this.randomInt(0, 10) > 4) {
return this.alphabetaChoice(this.game);
} else {
return this.randomChoice(this.game);
}
case 'hard':
case "hard":
return this.alphabetaChoice(this.game);
}
}
@@ -86,14 +86,12 @@ export class AI {
}
private maximize(alpha: number, beta: number, moves: Game[]) {
let result = {
const result = {
score: alpha,
game: moves[0]
};
for (let i = 0; i < moves.length; i++) {
const move = moves[i];
for (const move of moves) {
const alphabeta = this.alphabeta(move, alpha, beta);
if (alpha < alphabeta.score) {
alpha = alphabeta.score;
@@ -110,14 +108,12 @@ export class AI {
}
private minimize(alpha: number, beta: number, moves: Game[]) {
let result = {
const result = {
score: beta,
game: moves[0]
};
for (let i = 0; i < moves.length; i++) {
const move = moves[i];
for (const move of moves) {
const alphabeta = this.alphabeta(move, alpha, beta);
if (beta > alphabeta.score) {
beta = alphabeta.score;
@@ -139,5 +135,5 @@ export class AI {
}
export namespace AI {
export type Difficulty = 'easy' | 'normal' | 'hard';
export type Difficulty = "easy" | "normal" | "hard";
}

View File

@@ -1,4 +1,4 @@
type Token = 'x' | 'o';
type Token = "x" | "o";
type CellState = null | Token;
export { CellState, Token };

View File

@@ -1,3 +1,3 @@
type Difficulty = 'easy' | 'medium' | 'hard';
type Difficulty = "easy" | "medium" | "hard";
export default Difficulty;

View File

@@ -1,5 +1,5 @@
import { CellState } from './cell-state';
import Player from './player';
import { CellState } from "./cell-state";
import Player from "./player";
export default class Game {
private static readonly WINNING_STATES = [
@@ -13,11 +13,12 @@ export default class Game {
[2, 4, 6]
];
private board: CellState[] = [null, null, null, null, null, null, null, null, null];
public currentPlayer: Player;
public winner: Player | null = null;
public lastMove: number[];
private board: CellState[] = [null, null, null, null, null, null, null, null, null];
constructor(public firstPlayer: Player, public players: Player[] = [Player.HUMAN, Player.AI]) {
this.currentPlayer = firstPlayer;
}
@@ -45,15 +46,15 @@ export default class Game {
}
nextPlayer(): Player {
return this.players.find((player) => player !== this.currentPlayer) as Player;
return this.players.find(player => player !== this.currentPlayer) as Player;
}
remainingMoves(): number {
return this.board.filter((e) => e === null).length;
return this.board.filter(e => e === null).length;
}
isInWinningState(): boolean {
return Game.WINNING_STATES.some((winningState) => {
return Game.WINNING_STATES.some(winningState => {
return (
this.board[winningState[0]] !== null &&
this.board[winningState[0]] === this.board[winningState[1]] &&

View File

@@ -1,12 +1,8 @@
import { Token } from './cell-state';
import { Token } from "./cell-state";
export default class Player {
public static readonly HUMAN = new Player('x');
public static readonly AI = new Player('o');
public static readonly HUMAN = new Player("x");
public static readonly AI = new Player("o");
constructor(private _token: Token) {}
get token(): Token {
return this._token;
}
constructor(public token: Token) {}
}

View File

@@ -7,13 +7,10 @@
"~/plugins/*": ["./plugins/*"],
"~/components/*": ["./components/*"],
"~/pages/*": ["./pages/*"],
"~/assets/*": ["./assets/*"],
"~/assets/*": ["./assets/*"]
},
"strictPropertyInitialization": false,
"strict": true,
"types": [
"@types/node",
"@nuxt/vue-app"
],
},
"types": ["@types/node", "@nuxt/vue-app"]
}
}

View File

@@ -1,7 +1,12 @@
{
"defaultSeverity": "warning",
"extends": [
"tslint:recommended",
"tslint-config-prettier"
],
"extends": ["tslint:recommended", "tslint-config-prettier"],
"rules": {
"prettier": true,
"member-access": false,
"no-namespace": false,
"object-literal-sort-keys": false,
"ordered-imports": false
}
}