## tetrix in Scala: day 10

Yesterday we expanded the search tree of the tetrix-solving agent into second piece. Although the quality of the game it is able to play has improved, there are some more room for tweaking.

## tetrix in Scala: day 9

Yesterday we got the tetrix-solving agent to play a better game by fixing the heuristic function and evaluating 36 possible positions of the current piece.

### stop watch

Let's start by creating a function to measure the time it takes to run a segment of code:

```  private[this] def stopWatch[A](name: String)(arg: => A): A = {
val t0 = System.currentTimeMillis
val retval: A = arg
val t1 = System.currentTimeMillis
println(name + " took " + (t1 - t0).toString + " ms")
retval
}```

## tetrix in Scala: day 8

Yesterday we hooked up our tetrix-solving agent to an actor to take control of the game. Thus far the way it handled the game looked neither rational nor intelligent. After seeing many of the moves evaluated to 0.0 score including the heuristic penalties, I had two sneaking suspicions.

## tetrix in Scala: day 7

Yesterday we started on a new challange of building tetrix-solving AI. Russell and Norvig give insight into how a rational agent can be structured using a state machine , a utility function, and a tree searching algorithm. We have the first two, and a failing test:

```[info] Solver should
[info] + pick MoveLeft for s1
[error] x pick Drop for s3
[error]    'MoveLeft' is not equal to 'Drop' (AgentSpec.scala:13)```

## tetrix in Scala: day 6

Yesterday we improved the concurrent access of the game state by introducing a second actor. Now that we have a powerful tool to manage concurrency, we can venture out to somewhere new. Like taking over the mankind. One tetrix player at a time.

## tetrix in Scala: day 5

Yesterday we put in an Akka actor to manage concurrent access to the game state. Let's look at the abstract UI again:

```package com.eed3si9n.tetrix

class AbstractUI {
// skipping imports...
implicit val timeout = Timeout(1 second)

private[this] val initialState = Stage.newState(Block((0, 0), TKind) :: Nil,
randomStream(new util.Random))
private[this] val system = ActorSystem("TetrixSystem")
private[this] val playerActor = system.actorOf(Props(new StageActor(```

## tetrix in Scala: day 4

In the last few days, we implemented tetrix from the ground up. In the beginning I mentioned that I use this game to explore new ways of thinking. Since I had already implemented tetrix once in Scala, Scala alone really isn't anything new for me. The actual topic I wanted to think about using tetrix is the handling of concurrency.

## tetrix in Scala: day 3

Today's goal is to finish up the basic feature of Tetrix so it's playable.

### REPL

A few people in the community is coming up with best practices in Scala.

## tetrix in Scala: day 2

We have a failing test from yesterday, which is a cool way to end a day for a hobby project.

```[info] Moving to the left the current piece should
[info] + change the blocks in the view,
[error] x as long as it doesn't hit the wall
[error]    '(0,0), (-1,17), (0,17), (1,17), (0,18)' doesn't contain in order '(0,0), (0,17), (1,17), (2,17), (1,18)' (StageSpec.scala:8)```

## tetrix in Scala: day 1

Yesterday, we approximated the game state using `String`. Let's see how we can improve this.

### modeling the game

On screen there should be a 10x20 grid. I only want the current piece to be rendered in different color. We'll deal with the next piece window later. The different kinds of pieces can be represented using case objects:

```sealed trait PieceKind
case object IKind extends PieceKind
case object JKind extends PieceKind
case object LKind extends PieceKind
case object OKind extends PieceKind```