reversi 0.1.1

  • README.md
  • Installing
  • Versions
  • 35

Reversi in Dart

This repo implements the core algorithm for Reversi. No UI part.

Install

Install the console program:

pub global activate reversi

You may install the package locally:

dependencies:
  reversi: "^0.1.1"

Usage

Play our console program:

$ reversi
Please choose your side (B/b) Black, (W/w) White: b
  |a |b |c |d |e |f |g |h |  
1 |  |  |  |  |  |  |  |  |1 
2 |  |  |  |  |  |  |  |  |2 
3 |  |  |  |  |  |  |  |  |3 
4 |  |  |  |W |B |  |  |  |4 
5 |  |  |  |B |W |  |  |  |5 
6 |  |  |  |  |  |  |  |  |6 
7 |  |  |  |  |  |  |  |  |7 
8 |  |  |  |  |  |  |  |  |8 
  |a |b |c |d |e |f |g |h |  
Please move your disc (a1-h8): c4
  |a |b |c |d |e |f |g |h |  
1 |  |  |  |  |  |  |  |  |1 
2 |  |  |  |  |  |  |  |  |2 
3 |  |  |W |  |  |  |  |  |3 
4 |  |  |B |W |B |  |  |  |4 
5 |  |  |  |B |W |  |  |  |5 
6 |  |  |  |  |  |  |  |  |6 
7 |  |  |  |  |  |  |  |  |7 
8 |  |  |  |  |  |  |  |  |8 
  |a |b |c |d |e |f |g |h |  
Please move your disc (a1-h8): ...

Intro

Dart is a cross-platform programming language capable of web frontend, web backend, mobile, and console applications. The package implemented the core business logic for Reversi. You may utilize this package for diverse applications.

A sample code:

Board b = new Board();
Bot bot = new EasyBot(Disc.White);

// The game loop.
while (true) {
  // You have to implement your own drawBoard function.
  drawBoard(b);
  var isBlackMoved = false;
  var isWhiteMoved = false;

  // The round of black player, who is a man.
  var mbs = b.validMoves(Disc.Black);
  if (!mbs.isEmpty) {
    var mb;
    while (mb == null) {
      stdout.write('Please move your disc (a1-h8): ');
      String p = stdin.readLineSync();
      if (checkMove(p)) {
        var mb = str2Move(p);
        var s = new Set.from(mbs);

        if (s.contains(mb)) {
          b[mb] = Disc.Black;
        } else {
          stderr.writeln('Wrong move');
          continue;
        }

        break;
      } else {
        stderr.writeln('Invalid move');
      }
    }

    isBlackMoved = true;
  } else {
    stderr.writeln('No avaiable Black move');
  }

  // The round of white player, which is bot.
  var mws = b.validMoves(Disc.White);
  if (!mws.isEmpty) {
    var mw = bot.moveBy(b);
    b[mw] = Disc.White;
    isWhiteMoved = true;
  } else {
    stderr.writeln('No avaliable White move');
  }

  if (!isBlackMoved && !isWhiteMoved) {
    break;
  }
}

// Show the final result.
drawBoard(b);
stdout.writeln('Black: ' + b.black().toString());
stdout.writeln('White: ' + b.white().toString());

final w = b.win();
if (w == Win.Black) {
  stdout.writeln('Black player win');
} else if (w == Win.White) {
  stdout.writeln('White player win');
} else {
  stdout.writeln('Tie');
}

We shipped a console Reversi program for demo purpose. Currently, there is only one level of bot. See the source of our console program for more details. More bots and applicaions are on the way.

You may implement your own Reversi bot. You only need to fulfill this interface:

// Interface
abstract class Bot {
  Move moveBy(Board b) {
    // No implementation.
  }
}

// Implement your own bot.
class MyBot implements Bot {
  // Some fields and methods.

  @override
  Move moveBy(Board b) {
    // Implement it here.
  }
}

2017, Michael Chen

License

MIT

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  reversi: "^0.1.1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:reversi/reversi.dart';
        
Version Uploaded Documentation Archive
0.1.1 May 28, 2017 Go to the documentation of reversi 0.1.1 Download reversi 0.1.1 archive
0.1.0 May 28, 2017 failed Download reversi 0.1.0 archive

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
71 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
69 / 100
Overall score:
Weighted score of the above. [more]
35
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:reversi/reversi.dart.

Suggestions

  • Maintain CHANGELOG.md.

    Changelog entries help clients to follow the progress in your code.

  • Use constrained dependencies.

    The pubspec.yaml contains 1 dependency without version constraints. Specify version ranges for the following dependencies: algo.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 14 errors 4 hints.

    Strong-mode analysis of lib/board.dart failed with the following error:

    line: 419 col: 19
    The argument type 'Move' can't be assigned to the parameter type 'Disc'.

    Strong-mode analysis of lib/bot.dart failed with the following error:

    line: 4 col: 3
    Undefined class 'Move'.

    Similar analysis of the following files failed:

    • lib/easy_bot.dart (error)
    • lib/utils.dart (error)
  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • The description is too long.

    Search engines will display only the first part of the description. Try to keep it under 180 characters.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use reversi.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
algo 0.0.0
Dev dependencies
test ^0.12.20